-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (61 loc) · 2.68 KB
/
script.js
File metadata and controls
83 lines (61 loc) · 2.68 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
const isAPISupported = () => {
return window.File && window.FileReader && window.FileList && window.Blob;
}
const handleFileSelect = (event) => {
const selectedFile = event.target.files[0];
if (!selectedFile.type.match('video.*')) {
alert('Selecciona un archivo de video');
return;
}
const reader = new FileReader();
reader.onload = ((file) => {
return (e) => {
const videoContainer = document.querySelector('.video-container');
if (videoContainer) {
videoContainer.parentNode.removeChild(videoContainer);
}
const div = document.createElement('div');
div.id = 'video-div';
div.className = 'video-container';
div.innerHTML = `<video controls id="video" class="thumb" src="${e.target.result}" title="${escape(file.name)}"/>`;
document.getElementById('video-output').insertBefore(div, null);
const loadingMessage = document.createElement('p');
loadingMessage.id = 'loading';
loadingMessage.className = 'loading-message';
loadingMessage.innerHTML = 'El video se está cargando';
document.getElementById('video-output').insertBefore(loadingMessage, null);
const playButton = document.getElementById('play');
const pauseButton = document.getElementById('pause');
const volumeUpButton = document.getElementById('up');
const volumeDownButton = document.getElementById('down');
playButton.addEventListener('click', () => {
document.getElementById('video').play();
});
pauseButton.addEventListener('click', () => {
document.getElementById('video').pause();
});
volumeUpButton.addEventListener('click', () => {
document.getElementById('video').volume += 0.1;
});
volumeDownButton.addEventListener('click', () => {
document.getElementById('video').volume -= 0.1;
});
document.getElementById('video').addEventListener('canplay', () => {
const loadingMessage = document.getElementById('loading');
document.getElementById('video-output').removeChild(loadingMessage);
document.getElementById('video').style.visibility = 'visible';
playButton.style.visibility = 'visible';
pauseButton.style.visibility = 'visible';
volumeUpButton.style.visibility = 'visible';
volumeDownButton.style.visibility = 'visible';
});
}
})(selectedFile);
reader.readAsDataURL(selectedFile);
};
if (isAPISupported()) {
alert('Todas las API\'s están soportadas correctamente por el navegador');
} else {
alert('La API no está soportada por este navegador, prueba con Google Chrome');
}
document.getElementById('file').addEventListener('change', handleFileSelect, false);