-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupscript.js
47 lines (36 loc) · 1.66 KB
/
upscript.js
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
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>`;
}
// 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);
}