-
Notifications
You must be signed in to change notification settings - Fork 0
/
controls.js
114 lines (79 loc) · 2.45 KB
/
controls.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var audio = document.getElementById('narration');
var button = document.getElementById('mute');
button.onclick = function() {
if (audio.muted === false) {
audio.muted = true;
} else {
audio.muted = false;
}
};
var v = document.getElementById('video');
var playpause = document.getElementById('play-pause');
playpause.addEventListener(
'play',
function() {
v.play();
},
false);
playpause.onclick = function() {
if (v.paused) {
v.play();
} else {
v.pause();
}
return false;
};
var vid = document.getElementById("video");
vid.ontimeupdate = function() {
var percentage = (vid.currentTime / vid.duration) * 100;
$("#custom-seekbar span").css("width", percentage + "%");
};
$("#custom-seekbar").on("click", function(e) {
var offset = $(this).offset();
var left = (e.pageX - offset.left);
var totalWidth = $("#custom-seekbar").width();
var percentage = (left / totalWidth);
var vidTime = vid.duration * percentage;
vid.currentTime = vidTime;
}); //click()
const select = document.getElementById('streams');
const player = new YouTubeToHtml5({
selector: '.youtube-video-1',
attribute: 'data-yt',
autoload: false
});
player.addFilter('video.source', function(source, data, element, format, streams) {
if (Array.isArray(streams) && streams.length > 1) {
const options = streams;
options.sort(function(a, b) {
const aLabel = parseInt(a.label);
const bLabel = parseInt(b.label);
if (aLabel < bLabel) {
return -1;
}
if (aLabel > bLabel) {
return 1;
}
return 0;
});
for (let index = 0; index < options.length; index++) {
const stream = options[index];
const option = document.createElement('option');
option.value = stream.url;
const audioLabel = stream.hasAudio ? 'with audio' : 'without audio';
option.text = `${stream.label} ${audioLabel}`;
if (stream.url === source) {
option.setAttribute('selected', 'selected');
}
select.appendChild(option);
}
select.disabled = false;
select.addEventListener('change', function() {
element.src = this.value;
});
} else {
select.style.display = 'none';
}
return source;
});
player.load();