-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
240 lines (178 loc) · 5.66 KB
/
script.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
var player,
time_update_interval = 0;
function onYouTubeIframeAPIReady() {
player = new YT.Player('video-placeholder', {
width: 600,
height: 400,
videoId: 'Jch-LDFwnzw',
playerVars: {
html5: 1,
controls: 1,
showinfo: 0
},
events: {
onReady: initialize,
onStateChange: onPlayerStateChange,
onPlaybackRateChange: onPlayerPlaybackRateChange
}
});
ytLoaded = true;
}
function initialize() {
// Update the controls on load
updateTimerDisplay();
updateProgressBar();
// Clear any old interval.
clearInterval(time_update_interval);
// Start interval to update elapsed time display and
// the elapsed part of the progress bar every second.
time_update_interval = setInterval(function () {
updateTimerDisplay();
updateProgressBar();
}, 1000);
$('#volume-input').val(Math.round(player.getVolume()));
}
//modal slideshow
$("div[id^='myModal']").each(function () {
var currentModal = $(this);
//click next
currentModal.find('.btn-next').click(function () {
currentModal.modal('hide');
currentModal.closest("div[id^='myModal']").nextAll("div[id^='myModal']").first().modal('show');
});
//click prev
currentModal.find('.btn-prev').click(function () {
currentModal.modal('hide');
currentModal.closest("div[id^='myModal']").prevAll("div[id^='myModal']").first().modal('show');
});
});
$('.playlist').on('click', function () {
//console.log(this.value)
player.loadPlaylist({ list: this.value, listType: "playlist" });
});
// This function is called by initialize()
function updateTimerDisplay() {
// Update current time text display.
$('#current-time').text(formatTime(player.getCurrentTime()));
$('#duration').text(formatTime(player.getDuration()));
}
// This function is called by initialize()
function updateProgressBar() {
// Update the value of our progress bar accordingly.
$('#progress-bar').val((player.getCurrentTime() / player.getDuration()) * 100);
}
// Change video
//document.getElementById('pause').click();
//refresh()
$('#change-btn').on('click', function () {
var url = document.getElementById("channel").value;
//url = url.replace("watch?v=", "embed/");
//document.getElementById("video-placeholder").src = url;
if (url.includes("?t=")) {
var id = url.substring(url.indexOf('=') + 1, url.indexOf('?t='));
} else {
var id = url.substring(url.indexOf('=') + 1);
}
//var x = new String(id)
player.loadVideoById(id);
//$('#checkModal').modal('show');
});
// Progress bar
$('#progress-bar').on('mouseup touchend', function (e) {
// Calculate the new time for the video.
// new time in seconds = total duration in seconds * ( value of range input / 100 )
var newTime = player.getDuration() * (e.target.value / 100);
// Skip video to new time.
player.seekTo(newTime);
});
// Playback
$('#play').on('click', function () {
player.playVideo();
});
$('#pause').on('click', function () {
player.pauseVideo();
});
//pace control
$('#faster-btn').on('click', function () {
//playbackrate[playbackrate.indexOf[player.getPlaybackRate()]+1];
playbackrate = player.getAvailablePlaybackRates();
idx = playbackrate.indexOf(player.getPlaybackRate()) + 1;
console.log(playbackrate[idx]);
if (idx > playbackrate.length) {
alert("cannot play any faster");
} else {
player.setPlaybackRate(playbackrate[idx]);
}
});
$('#slower-btn').on('click', function () {
//playbackrate[playbackrate.indexOf[player.getPlaybackRate()]+1];
playbackrate = player.getAvailablePlaybackRates();
idx = playbackrate.indexOf(player.getPlaybackRate()) - 1;
console.log(playbackrate[idx]);
if (idx < 0) {
alert("can't play any slower");
} else {
player.setPlaybackRate(playbackrate[idx]);
}
//can't play any slower
});
// Sound volume
$('#mute-toggle').on('click', function () {
var mute_toggle = $(this);
if (player.isMuted()) {
player.unMute();
mute_toggle.text('volume_up');
}
else {
player.mute();
mute_toggle.text('volume_off');
}
});
$('#volume-input-up').on('click', function () {
player.setVolume(player.getVolume() + 35);
});
$('#volume-input-down').on('click', function () {
player.setVolume(player.getVolume() - 35);
});
// Other options
$('#speed').on('change', function () {
player.setPlaybackRate($(this).val());
});
$('#quality').on('change', function () {
player.setPlaybackQuality($(this).val());
});
//skip to other places in the video
$('#skip-btn').on('click', function () {
player.seekTo(player.getCurrentTime() + parseInt($("#skip-btn").val()), true);
});
$('#back-btn').on('click', function () {
player.seekTo(player.getCurrentTime() - parseInt($("#back-btn").val()), true);
});
// Playlist
$('#next').on('click', function () {
player.nextVideo()
});
$('#prev').on('click', function () {
player.previousVideo()
});
// Load video
$('.thumbnail').on('click', function () {
var url = $(this).attr('data-video-id');
player.cueVideoById(url);
});
// Helper Functions
function formatTime(time) {
time = Math.round(time);
var minutes = Math.floor(time / 60),
seconds = time - minutes * 60;
seconds = seconds < 10 ? '0' + seconds : seconds;
return minutes + ":" + seconds;
}
function onPlayerStateChange(event) {
}
function onPlayerPlaybackRateChange(playbackRate) {
console.log(player.getPlaybackRate());
}
$('pre code').each(function (i, block) {
hljs.highlightBlock(block);
});