-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.html
71 lines (61 loc) · 2.13 KB
/
temp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<title>Media Upload</title>
<style>
/* Add some basic styling */
body {
font-family: Arial, sans-serif;
margin: 20px;
}
input[type="file"] {
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Upload Media</h1>
<input type="file" id="mediaFile" accept="audio/*, video/*" />
<div id="mediaInfo"></div>
<script>
const mediaFileInput = document.getElementById('mediaFile');
const mediaInfoDiv = document.getElementById('mediaInfo');
mediaFileInput.addEventListener('change', handleMediaUpload);
function handleMediaUpload() {
const file = mediaFileInput.files[0];
if (file) {
displayMediaInfo(file);
}
}
function displayMediaInfo(file) {
const mediaType = file.type.startsWith('audio') ? 'Audio' : 'Video';
const mediaDuration = (file.duration || 'N/A');
mediaInfoDiv.innerHTML = '<p>${mediaType} duration: ${mediaDuration}</p>';
}
</script>
<script>
// The JavaScript code will handle the media file upload and display the duration of the uploaded media.
// It will use the HTML5 FileReader API to read the media file and extract the duration.
function handleMediaUpload() {
const file = mediaFileInput.files[0];
if (file) {
displayMediaInfo(file);
}
}
function displayMediaInfo(file) {
const mediaType = file.type.startsWith('audio') ? 'Audio' : 'Video';
// Use the HTML5 FileReader API to read the media file
const reader = new FileReader();
reader.onload = function (event) {
const mediaElement = document.createElement(mediaType.toLowerCase());
mediaElement.src = event.target.result;
mediaElement.addEventListener('loadedmetadata', function () {
const mediaDuration = mediaElement.duration.toFixed(2); // Duration in seconds
mediaInfoDiv.innerHTML = `<p>${mediaType} duration: ${mediaDuration} seconds</p>`;
});
};
reader.readAsDataURL(file);
}
</script>
</body>
</html>