forked from videojs/videojs-playlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
293 lines (244 loc) · 8.38 KB
/
index.html
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>videojs-playlist Demo</title>
<link href="node_modules/video.js/dist/video-js.css" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
background-color: #f4f4f4;
}
.controls {
margin-top: 20px;
display: flex;
gap: 10px;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 15px;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
.playlist-info {
margin-top: 20px;
background-color: #fff;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
ul {
list-style: none;
padding: 0;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.playlist-display {
margin-top: 20px;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.playlist-item {
border: 1px solid #ddd;
border-radius: 5px;
padding: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
background-color: #fff;
}
.playlist-item:hover {
background-color: #007bff;
}
.playlist-item img {
max-width: 100px;
height: auto;
border-radius: 5px;
}
.playlist-item p {
margin: 5px 0 0;
font-size: 14px;
}
.input-group {
margin-top: 10px;
}
input[type="number"] {
padding: 10px;
border-radius: 5px;
border: 1px solid #ddd;
width: 50px;
}
</style>
</head>
<body>
<!-- Video Player -->
<video id="videojs-playlist-player" class="video-js vjs-default-skin" controls width="640" height="360"></video>
<!-- Playlist Control Buttons -->
<div class="controls">
<button id="prevBtn">Previous</button>
<button id="nextBtn">Next</button>
<button id="firstBtn">First</button>
<button id="lastBtn">Last</button>
<button id="addBtn">Add</button>
<button id="removeBtn">Remove</button>
<button id="reverseBtn">Reverse</button>
<button id="sortBtn">Sort</button>
<button id="shuffleBtn">Shuffle</button>
</div>
<div class="input-group">
<label for="removeIndexInput">Remove from index:</label>
<input id="removeIndexInput" type="number" value="0" min="0">
<label for="removeCountInput">Number of items to remove:</label>
<input id="removeCountInput" type="number" value="1" min="0">
<label for="addIndexInput">Index to add item:</label>
<input id="addIndexInput" type="number" value="0" min="0">
</div>
<!-- Playlist Information -->
<div id="playlistInfo" class="playlist-info">
Current Index: <span id="currentIndex">-</span><br>
Next Index: <span id="nextIndex">-</span><br>
Previous Index: <span id="prevIndex">-</span><br>
Last Index: <span id="lastIndex">-</span><br>
Repeat: <span id="repeat">-</span><br>
Autoadvance Delay: <span id="autoadvance">-</span>
</div>
<!-- Playlist Display -->
<div id="playlistDisplay" class="playlist-display">
<!-- Playlist items will be added here dynamically -->
</div>
<ul>
<li><a href="/test/debug.html">Run unit tests in browser</a></li>
</ul>
<!-- JavaScript -->
<script src="node_modules/video.js/dist/video.js"></script>
<script src="dist/videojs-playlist.js"></script>
<script>
// Initialize Video.js Player
const player = videojs('videojs-playlist-player');
// Plugin event listeners. All are triggered on the player.
player.on([
'playlistchange', 'playlistsorted',
'beforeplaylistitem', 'playlistitem',
'playlistadd', 'playlistremove'
], (e, data) => {
videojs.log('player saw "' + e.type + '"', e);
videojs.log('event data:', data);
});
// Initialize PlaylistPlugin
const playlistPlugin = player.playlistPlugin(player, {});
const PlaylistPluginClass = videojs.getPlugin('playlistPlugin');
const videoList = [{
sources: [{ src: 'http://media.w3.org/2010/05/sintel/trailer.mp4', type: 'video/mp4' }],
poster: 'http://media.w3.org/2010/05/sintel/poster.png'
}, {
sources: [{ src: 'http://vjs.zencdn.net/v/oceans.mp4', type: 'video/mp4' }, { src: 'http://vjs.zencdn.net/v/oceans.mp4?duplicate=true', type: 'video/mp4' }],
poster: 'https://image.mux.com/5g1hMA6dKAe8DCgBB901DYB200U65ev2y00/thumbnail.jpg?time=43'
}, {
sources: [{ src: 'http://media.w3.org/2010/05/video/movie_300.mp4', type: 'video/mp4' }],
poster: 'http://media.w3.org/2010/05/video/poster.png'
}];
const playlist = PlaylistPluginClass.createPlaylistFrom(videoList);
// Playlist methods
playlist.shuffle();
playlist.enableRepeat();
// Plugin methods
playlistPlugin.loadPlaylist(playlist);
playlistPlugin.loadFirstItem();
playlistPlugin.setAutoadvanceDelay(0);
// Update Playlist Information
function updatePlaylistInfo() {
document.getElementById('currentIndex').textContent = playlist.getCurrentIndex();
document.getElementById('lastIndex').textContent = playlist.getLastIndex();
document.getElementById('nextIndex').textContent = playlist.getNextIndex();
document.getElementById('prevIndex').textContent = playlist.getPreviousIndex();
document.getElementById('repeat').textContent = playlist.isRepeatEnabled();
document.getElementById('autoadvance').textContent = playlistPlugin.getAutoadvanceDelay();
}
// Update the Playlist Display UI
function updatePlaylistDisplay() {
const display = document.getElementById('playlistDisplay');
display.innerHTML = '';
playlist.get().forEach(function (item, index) {
const itemDiv = document.createElement('div');
itemDiv.classList.add('playlist-item');
itemDiv.addEventListener('click', function () {
playlistPlugin.loadPlaylistItem(index);
updatePlaylistInfo();
});
const img = document.createElement('img');
img.src = item.poster || 'placeholder.jpg';
itemDiv.appendChild(img);
const title = document.createElement('p');
title.textContent = `Item ${index + 1}`;
itemDiv.appendChild(title);
display.appendChild(itemDiv);
});
}
// Initial calls
updatePlaylistDisplay();
updatePlaylistInfo();
player.on(['playlistchange', 'playlistsorted', 'playlistadd', 'playlistremove', 'playlistitem'], () => {
updatePlaylistDisplay();
updatePlaylistInfo();
});
// Control Button Event Listeners
const controls = document.querySelector('.controls');
controls.addEventListener('click', function (event) {
const buttonId = event.target.id;
switch (buttonId) {
case 'prevBtn':
playlistPlugin.loadPreviousItem();
break;
case 'nextBtn':
playlistPlugin.loadNextItem();
break;
case 'firstBtn':
playlistPlugin.loadFirstItem();
break;
case 'lastBtn':
playlistPlugin.loadLastItem();
break;
case 'addBtn':
const addIndex = parseInt(document.getElementById('addIndexInput').value, 10);
// Add the same source URL but with a different poster so it is possible to differentiate
const added = playlist.add({
sources: [{ src: 'http://vjs.zencdn.net/v/oceans.mp4', type: 'video/mp4' }],
poster: `https://image.mux.com/5g1hMA6dKAe8DCgBB901DYB200U65ev2y00/thumbnail.jpg?time=${Math.floor(Math.random() * 30) + 1}`
}, addIndex);
videojs.log('added items:', added);
break;
case 'removeBtn':
const removeIndex = parseInt(document.getElementById('removeIndexInput').value, 10);
const removeCount = parseInt(document.getElementById('removeCountInput').value, 10);
const removed = playlist.remove(removeIndex, removeCount);
videojs.log('removed items:', removed);
break;
case 'reverseBtn':
playlist.reverse();
break;
case 'sortBtn':
playlist.sort((a, b) => a.sources[0].src.localeCompare(b.sources[0].src));
break;
case 'shuffleBtn':
playlist.shuffle();
break;
}
});
</script>
</body>
</html>