-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_video_player.js
More file actions
50 lines (39 loc) · 1.31 KB
/
local_video_player.js
File metadata and controls
50 lines (39 loc) · 1.31 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
var URL = window.URL || window.webkitURL
var wavesurfer_script = document.createElement('script');
wavesurfer_script.setAttribute('src','https://cdnjs.cloudflare.com/ajax/libs/wavesurfer.js/2.0.4/wavesurfer.min.js');
document.head.appendChild(wavesurfer_script);
var videoPlayer = document.getElementById('player');
function videoDefaultSize(){
videoPlayer.style.width = "50%";
}
function video2XSize(){
videoPlayer.style.width = "100%";
}
function loadWaveform(){
var wavesurfer = WaveSurfer.create({
container: document.querySelector('#audio-waveform'),
waveColor: '#A8DBA8',
progressColor: '#3B8686',
backend: 'MediaElement'
});
// Load audio from existing media element
var mediaElt = document.querySelector('video');
wavesurfer.load(mediaElt);
mediaElt.setAttribute("controls","controls");
}
var playSelectedFile = function (event) {
var file = this.files[0];
var type = file.type;
var videoNode = document.querySelector('video');
var canPlay = videoNode.canPlayType(type);
if (canPlay === '') {canPlay = 'no'};
var isError = canPlay === 'no';
if (isError) {
return;
}
var fileURL = URL.createObjectURL(file);
videoNode.src = fileURL;
loadWaveform();
}
var inputNode = document.querySelector('#selector')
inputNode.addEventListener('change', playSelectedFile, false)