-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream-admin.html
More file actions
807 lines (697 loc) · 33.7 KB
/
Copy pathstream-admin.html
File metadata and controls
807 lines (697 loc) · 33.7 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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Stream Admin - Jungle Radio</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<link rel="icon" href="phoenix-new.jpg" type="image/jpeg">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #1a1a1a 0%, #2d1b2e 100%);
color: #fff;
height: 100vh;
overflow: hidden;
position: relative;
font-size: 12px;
}
.container {
max-width: 100vw;
height: 100vh;
margin: 0;
padding: 10px;
display: flex;
flex-direction: column;
overflow: hidden;
}
.header {
text-align: center;
margin-bottom: 8px;
padding: 8px 15px;
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
backdrop-filter: blur(10px);
flex-shrink: 0;
}
.header h1 {
color: #ff6b35;
margin: 0;
font-size: 1.3rem;
}
.header p {
color: #ccc;
font-size: 10px;
margin-top: 3px;
}
.btn {
padding: 4px 10px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 11px;
font-weight: bold;
text-decoration: none;
display: inline-block;
transition: all 0.2s ease;
margin: 2px;
}
.btn-primary {
background: linear-gradient(45deg, #ff6b35, #f7931e);
color: white;
}
.btn-success {
background: #2ecc71;
color: white;
}
.btn-danger {
background: #e74c3c;
color: white;
}
.btn:hover {
opacity: 0.9;
transform: translateY(-1px);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.hidden {
display: none;
}
.message-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 1000;
max-width: 300px;
}
.message {
background: rgba(255, 255, 255, 0.95);
padding: 15px 20px;
border-radius: 8px;
margin-bottom: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
animation: slideIn 0.3s ease;
}
@keyframes slideIn {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.message.success {
border-left: 4px solid #2ecc71;
color: #2ecc71;
}
.message.error {
border-left: 4px solid #e74c3c;
color: #e74c3c;
}
.message.info {
border-left: 4px solid #3498db;
color: #3498db;
}
.stream-panel {
background: rgba(255, 255, 255, 0.1);
padding: 10px;
border-radius: 10px;
backdrop-filter: blur(10px);
flex: 1;
overflow: hidden;
display: flex;
flex-direction: column;
}
.nav-bar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
padding: 6px;
background: rgba(0,0,0,0.2);
border-radius: 4px;
}
.nav-bar h2 {
margin: 0;
font-size: 1rem;
color: #ff6b35;
}
.nav-links {
display: flex;
gap: 8px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1><i class="fas fa-broadcast-tower"></i> Live Stream Admin</h1>
<p style="font-size: 10px; margin-top: 3px;">Jungle Radio - Stream Management System</p>
</div>
<div id="messageContainer" class="message-container"></div>
<!-- Stream Management Panel -->
<div class="stream-panel">
<div class="nav-bar">
<h2><i class="fas fa-list"></i> Playlist Manager</h2>
<div class="nav-links">
<a href="admin.html" class="btn" style="background: #3498db; color: white;">
<i class="fas fa-tasks"></i> Queue Admin
</a>
<a href="stream.html" target="_blank" class="btn btn-success">
<i class="fas fa-external-link-alt"></i> View Stream
</a>
</div>
</div>
<!-- Stream Section -->
<div style="display: flex; flex-direction: column; height: 100%; overflow: hidden;">
<!-- Compact Controls Area -->
<div style="flex-shrink: 0; background: rgba(0,0,0,0.2); padding: 8px; border-radius: 4px; margin-bottom: 8px;">
<!-- Stats Row -->
<div style="display: flex; gap: 8px; margin-bottom: 6px; font-size: 8px;">
<div style="flex: 1; background: rgba(52, 152, 219, 0.2); padding: 4px; border-radius: 3px; text-align: center;">
<div style="font-weight: bold; color: #3498db;">Status</div>
<div id="streamStatus" style="color: #ccc; font-size: 9px;">Offline</div>
</div>
<div style="flex: 1; background: rgba(46, 204, 113, 0.2); padding: 4px; border-radius: 3px; text-align: center;">
<div style="font-weight: bold; color: #2ecc71;">Songs</div>
<div style="color: #ccc; font-size: 9px;"><span id="playlistCount">0</span></div>
</div>
<div style="flex: 1; background: rgba(155, 89, 182, 0.2); padding: 4px; border-radius: 3px; text-align: center;">
<div style="font-weight: bold; color: #9b59b6;">Position</div>
<div id="currentPosition" style="color: #ccc; font-size: 9px;">--:--</div>
</div>
</div>
<!-- Currently Playing (Compact) -->
<div id="currentVideoDisplay" style="padding: 6px; text-align: center; color: #ccc; font-size: 9px; background: rgba(255,255,255,0.05); border-radius: 3px; margin-bottom: 6px;">
No video playing
</div>
<!-- Compact Media Controls -->
<div style="display: flex; gap: 4px; margin-bottom: 6px; justify-content: center;">
<button id="previousBtn" class="btn" style="background: #9b59b6; color: white; padding: 4px 8px; font-size: 8px;">
<i class="fas fa-step-backward"></i>
</button>
<button id="playBtn" class="btn btn-success" style="padding: 4px 10px; font-size: 8px;">
<i class="fas fa-play"></i> Play
</button>
<button id="pauseBtn" class="btn" style="background: #f39c12; color: white; padding: 4px 8px; font-size: 8px;">
<i class="fas fa-pause"></i>
</button>
<button id="stopBtn" class="btn btn-danger" style="padding: 4px 8px; font-size: 8px;">
<i class="fas fa-stop"></i>
</button>
<button id="nextBtn" class="btn" style="background: #9b59b6; color: white; padding: 4px 8px; font-size: 8px;">
<i class="fas fa-step-forward"></i>
</button>
<button id="restartBtn" class="btn" style="background: #3498db; color: white; padding: 4px 8px; font-size: 8px;">
<i class="fas fa-redo"></i>
</button>
<button id="shuffleCurrentBtn" class="btn" style="background: #e67e22; color: white; padding: 4px 8px; font-size: 8px;">
<i class="fas fa-random"></i>
</button>
</div>
<!-- Add Video Form (Compact) -->
<div style="display: flex; gap: 4px; align-items: center;">
<input type="text" id="videoUrl" placeholder="YouTube URL or ID" style="flex: 1; padding: 4px; font-size: 8px; border-radius: 3px; border: 1px solid #555; background: rgba(0,0,0,0.3); color: white;">
<button id="addVideoBtn" class="btn btn-primary" style="padding: 4px 8px; font-size: 8px;">
<i class="fas fa-plus"></i>
</button>
<button id="playNowBtn" class="btn btn-success" style="padding: 4px 8px; font-size: 8px;">
<i class="fas fa-play"></i>
</button>
<button id="refreshTitlesBtn" class="btn" style="background: #3498db; color: white; padding: 4px 8px; font-size: 8px;" title="Refresh video titles from YouTube">
<i class="fas fa-sync"></i>
</button>
<button id="shufflePlaylistBtn" class="btn" style="background: #9b59b6; color: white; padding: 4px 8px; font-size: 8px;">
<i class="fas fa-random"></i>
</button>
<button id="clearPlaylistBtn" class="btn btn-danger" style="padding: 4px 8px; font-size: 8px;">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
<!-- Playlist Management (Takes up remaining space) -->
<div style="flex: 1; display: flex; flex-direction: column; min-height: 0; background: rgba(0,0,0,0.2); border-radius: 4px; overflow: hidden;">
<div style="display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; background: rgba(255, 107, 53, 0.2); flex-shrink: 0;">
<div style="font-weight: bold; color: #ff6b35; font-size: 10px;">
<i class="fas fa-list"></i> Stream Playlist (<span id="playlistCountHeader">0</span> songs)
</div>
<div style="font-size: 8px; color: #999;">
<i class="fas fa-circle" style="color: #2ecc71;"></i> = Playing |
<i class="fas fa-star" style="color: #f39c12;"></i> = Favorite |
Use <i class="fas fa-arrow-up"></i><i class="fas fa-arrow-down"></i> to reorder
</div>
</div>
<div id="playlistItems" style="flex: 1; overflow-y: auto; background: rgba(0,0,0,0.3);"></div>
</div>
</div>
</div>
</div>
<!-- Local Stream Manager -->
<script src="local-stream.js"></script>
<script type="module">
class StreamAdmin {
constructor() {
this.playlist = [];
this.currentVideo = null;
this.streamManager = null;
this.init();
}
async init() {
this.initLocalStorage();
this.bindEvents();
this.loadStreamData();
}
initLocalStorage() {
if (typeof LocalStreamManager !== 'undefined') {
this.streamManager = new LocalStreamManager();
console.log('LocalStreamManager initialized');
} else {
console.warn('LocalStreamManager not found');
}
}
bindEvents() {
// Media controls
const previousBtn = document.getElementById('previousBtn');
if (previousBtn) {
previousBtn.addEventListener('click', () => this.playPreviousVideo());
}
const playBtn = document.getElementById('playBtn');
if (playBtn) {
playBtn.addEventListener('click', () => this.resumeStream());
}
const pauseBtn = document.getElementById('pauseBtn');
if (pauseBtn) {
pauseBtn.addEventListener('click', () => this.pauseStream());
}
const stopBtn = document.getElementById('stopBtn');
if (stopBtn) {
stopBtn.addEventListener('click', () => this.stopStream());
}
const nextBtn = document.getElementById('nextBtn');
if (nextBtn) {
nextBtn.addEventListener('click', () => this.playNextVideoFromAdmin());
}
const restartBtn = document.getElementById('restartBtn');
if (restartBtn) {
restartBtn.addEventListener('click', () => this.restartCurrentVideo());
}
const shuffleCurrentBtn = document.getElementById('shuffleCurrentBtn');
if (shuffleCurrentBtn) {
shuffleCurrentBtn.addEventListener('click', () => this.playRandomVideo());
}
// Add video controls
const addVideoBtn = document.getElementById('addVideoBtn');
if (addVideoBtn) {
addVideoBtn.addEventListener('click', () => this.addVideoToPlaylist());
}
const playNowBtn = document.getElementById('playNowBtn');
if (playNowBtn) {
playNowBtn.addEventListener('click', () => this.playVideoNow());
}
// Playlist controls
const refreshTitlesBtn = document.getElementById('refreshTitlesBtn');
if (refreshTitlesBtn) {
refreshTitlesBtn.addEventListener('click', () => this.forceRefreshTitles());
}
const shufflePlaylistBtn = document.getElementById('shufflePlaylistBtn');
if (shufflePlaylistBtn) {
shufflePlaylistBtn.addEventListener('click', () => this.shufflePlaylist());
}
const clearPlaylistBtn = document.getElementById('clearPlaylistBtn');
if (clearPlaylistBtn) {
clearPlaylistBtn.addEventListener('click', () => this.clearPlaylist());
}
}
loadStreamData() {
if (!this.streamManager) {
console.warn('Stream manager not initialized yet');
return;
}
this.currentVideo = this.streamManager.getCurrentVideo();
this.updateCurrentVideoDisplay();
this.playlist = this.streamManager.getPlaylist();
// Resolve video titles for existing videos
this.resolvePlaylistTitles();
this.updatePlaylistDisplay();
this.updatePlaylistCount();
}
async resolvePlaylistTitles() {
if (!this.playlist || this.playlist.length === 0) return;
let updated = false;
const resolvedPlaylist = [];
for (const video of this.playlist) {
// Only fetch if title is generic "Video {id}"
if (video.title && video.title.startsWith('Video ') && video.title.length < 30) {
try {
const videoInfo = await this.getVideoInfo(video.videoId);
// Preserve favorite marking and other metadata
resolvedPlaylist.push({
...video,
title: videoInfo.title,
author: videoInfo.author || video.author
});
updated = true;
} catch (error) {
console.error(`Failed to resolve video ${video.videoId}:`, error);
resolvedPlaylist.push(video);
}
} else {
resolvedPlaylist.push(video);
}
}
if (updated) {
this.playlist = resolvedPlaylist;
this.streamManager.savePlaylist(resolvedPlaylist);
this.updatePlaylistDisplay();
}
}
async forceRefreshTitles() {
if (!this.playlist || this.playlist.length === 0) {
this.showMessage('Playlist is empty', 'info');
return;
}
this.showMessage('Refreshing video titles...', 'info');
const resolvedPlaylist = [];
for (let i = 0; i < this.playlist.length; i++) {
const video = this.playlist[i];
try {
const videoInfo = await this.getVideoInfo(video.videoId);
resolvedPlaylist.push({
...video,
title: videoInfo.title,
author: videoInfo.author || video.author
});
// Update display in real-time
if (i % 10 === 0) {
this.showMessage(`Refreshed ${i + 1}/${this.playlist.length} titles...`, 'info');
}
} catch (error) {
console.error(`Failed to resolve video ${video.videoId}:`, error);
resolvedPlaylist.push(video);
}
}
this.playlist = resolvedPlaylist;
this.streamManager.savePlaylist(resolvedPlaylist);
this.updatePlaylistDisplay();
this.showMessage('All titles refreshed!', 'success');
}
updateCurrentVideoDisplay() {
const container = document.getElementById('currentVideoDisplay');
if (!container) return;
if (!this.currentVideo) {
container.innerHTML = 'No video playing';
document.getElementById('streamStatus').textContent = 'Offline';
return;
}
document.getElementById('streamStatus').textContent = 'Live';
container.innerHTML = `
<strong style="color: #2ecc71;">${this.escapeHtml(this.currentVideo.title || 'Unknown')}</strong>
`;
}
updatePlaylistDisplay() {
const container = document.getElementById('playlistItems');
container.innerHTML = '';
if (this.playlist.length === 0) {
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #ccc; font-size: 9px;">No videos in playlist</div>';
return;
}
this.playlist.forEach((video, index) => {
const item = document.createElement('div');
const isFavorite = video.isFavorite || video.source === 'favorite';
item.style.cssText = 'display: grid; grid-template-columns: 35px 1fr 80px 160px; gap: 8px; padding: 6px 10px; border-bottom: 1px solid rgba(255,255,255,0.1); align-items: center; font-size: 9px;';
// Different background for favorites
if (isFavorite) {
item.style.background = 'rgba(243, 156, 18, 0.15)';
item.style.borderLeft = '3px solid #f39c12';
} else if (this.currentVideo && this.currentVideo.videoId === video.videoId) {
item.style.background = 'rgba(46, 204, 113, 0.15)';
item.style.borderLeft = '3px solid #2ecc71';
}
item.innerHTML = `
<div style="text-align: center; font-weight: bold; color: #ff6b35; font-size: 10px;">${index + 1}</div>
<div style="min-width: 0;">
<div style="font-weight: bold; color: #ff6b35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px;" title="${this.escapeHtml(video.title)}">
${isFavorite ? '<i class="fas fa-star" style="color: #f39c12; margin-right: 4px;"></i>' : ''}${this.escapeHtml(video.title)}
</div>
<div style="font-size: 8px; color: #999; margin-top: 2px;">
<a href="https://www.youtube.com/watch?v=${video.videoId}" target="_blank" style="color: #3498db; text-decoration: none;">
<i class="fas fa-external-link-alt"></i> ${video.videoId}
</a>
${video.addedBy ? ` • ${this.escapeHtml(video.addedBy)}` : ''}
${isFavorite ? ' • <span style="color: #f39c12;">Favorite</span>' : ''}
</div>
</div>
<div style="text-align: center; color: #ccc; font-size: 9px;">${video.duration || 'Unknown'}</div>
<div style="display: flex; gap: 3px; justify-content: center;">
<button class="btn btn-success" onclick="streamAdmin.playVideoAtIndex(${index})" style="padding: 3px 6px; font-size: 8px;" title="Play Now">
<i class="fas fa-play"></i>
</button>
<button class="btn" style="background: #3498db; color: white; padding: 3px 6px; font-size: 8px;" onclick="streamAdmin.moveVideoUp(${index})" ${index === 0 ? 'disabled' : ''} title="Move Up">
<i class="fas fa-arrow-up"></i>
</button>
<button class="btn" style="background: #3498db; color: white; padding: 3px 6px; font-size: 8px;" onclick="streamAdmin.moveVideoDown(${index})" ${index === this.playlist.length - 1 ? 'disabled' : ''} title="Move Down">
<i class="fas fa-arrow-down"></i>
</button>
<button class="btn btn-danger" onclick="streamAdmin.removeVideoFromPlaylist(${index})" style="padding: 3px 6px; font-size: 8px;" title="Remove">
<i class="fas fa-trash"></i>
</button>
</div>
`;
container.appendChild(item);
});
this.updatePlaylistCount();
}
updatePlaylistCount() {
const count = this.playlist ? this.playlist.length : 0;
const countElement = document.getElementById('playlistCount');
const countHeaderElement = document.getElementById('playlistCountHeader');
if (countElement) countElement.textContent = count;
if (countHeaderElement) countHeaderElement.textContent = count;
}
extractVideoId(url) {
const regex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
const match = url.match(regex);
return match ? match[1] : url;
}
async getVideoInfo(videoId) {
try {
// Try to fetch video info from YouTube oEmbed API
const response = await fetch(`https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${videoId}&format=json`);
if (response.ok) {
const data = await response.json();
return {
videoId: videoId,
title: data.title || `Video ${videoId}`,
duration: 'Unknown',
thumbnail: data.thumbnail_url || `https://img.youtube.com/vi/${videoId}/mqdefault.jpg`,
author: data.author_name || 'Unknown'
};
}
} catch (error) {
console.error('Error fetching video info:', error);
}
// Fallback if API fails
return {
videoId: videoId,
title: `Video ${videoId}`,
duration: 'Unknown',
thumbnail: `https://img.youtube.com/vi/${videoId}/mqdefault.jpg`
};
}
async addVideoToPlaylist() {
const url = document.getElementById('videoUrl').value.trim();
if (!url) {
this.showMessage('Please enter a YouTube URL or video ID', 'error');
return;
}
try {
const videoId = this.extractVideoId(url);
const videoInfo = await this.getVideoInfo(videoId);
if (this.streamManager) {
this.streamManager.addToPlaylist(videoInfo);
this.playlist = this.streamManager.getPlaylist();
this.updatePlaylistDisplay();
}
document.getElementById('videoUrl').value = '';
this.showMessage('Video added to playlist!', 'success');
} catch (error) {
console.error('Error adding video:', error);
this.showMessage('Error adding video: ' + error.message, 'error');
}
}
async playVideoNow() {
const url = document.getElementById('videoUrl').value.trim();
if (!url) {
this.showMessage('Please enter a YouTube URL or video ID', 'error');
return;
}
try {
const videoId = this.extractVideoId(url);
const videoInfo = await this.getVideoInfo(videoId);
if (this.streamManager) {
this.currentVideo = this.streamManager.setCurrentVideo(videoInfo);
this.updateCurrentVideoDisplay();
document.getElementById('streamStatus').textContent = 'Live';
}
document.getElementById('videoUrl').value = '';
this.showMessage('Now playing!', 'success');
} catch (error) {
console.error('Error playing video:', error);
this.showMessage('Error playing video: ' + error.message, 'error');
}
}
playVideoAtIndex(index) {
if (index < 0 || index >= this.playlist.length) return;
const video = this.playlist[index];
if (this.streamManager) {
this.currentVideo = this.streamManager.setCurrentVideo(video);
this.updateCurrentVideoDisplay();
this.updatePlaylistDisplay();
this.showMessage('Now playing: ' + video.title, 'success');
}
}
removeVideoFromPlaylist(index) {
if (index < 0 || index >= this.playlist.length) return;
if (this.streamManager) {
this.playlist = this.streamManager.removeFromPlaylist(index);
this.updatePlaylistDisplay();
this.showMessage('Video removed from playlist', 'success');
}
}
moveVideoUp(index) {
if (index <= 0 || index >= this.playlist.length) return;
if (this.streamManager) {
const playlist = this.streamManager.getPlaylist();
[playlist[index - 1], playlist[index]] = [playlist[index], playlist[index - 1]];
this.streamManager.savePlaylist(playlist);
this.playlist = playlist;
this.updatePlaylistDisplay();
}
}
moveVideoDown(index) {
if (index < 0 || index >= this.playlist.length - 1) return;
if (this.streamManager) {
const playlist = this.streamManager.getPlaylist();
[playlist[index], playlist[index + 1]] = [playlist[index + 1], playlist[index]];
this.streamManager.savePlaylist(playlist);
this.playlist = playlist;
this.updatePlaylistDisplay();
}
}
shufflePlaylist() {
if (this.playlist.length < 2) {
this.showMessage('Need at least 2 videos to shuffle', 'error');
return;
}
if (this.streamManager) {
this.playlist = this.streamManager.shufflePlaylist();
this.updatePlaylistDisplay();
this.showMessage('Playlist shuffled!', 'success');
}
}
clearPlaylist() {
if (!confirm('Are you sure you want to clear the entire playlist?')) return;
if (this.streamManager) {
this.streamManager.savePlaylist([]);
this.playlist = [];
this.updatePlaylistDisplay();
this.showMessage('Playlist cleared!', 'success');
}
}
playNextVideoFromAdmin() {
if (this.streamManager) {
const nextVideo = this.streamManager.playNextVideo();
if (nextVideo) {
this.currentVideo = nextVideo;
this.updateCurrentVideoDisplay();
this.updatePlaylistDisplay();
this.showMessage('Playing next video', 'success');
} else {
this.showMessage('No more videos in playlist', 'info');
}
}
}
playPreviousVideo() {
const playlist = this.playlist;
if (!playlist.length) {
this.showMessage('Playlist is empty', 'info');
return;
}
const currentIndex = this.currentVideo ?
playlist.findIndex(v => v.videoId === this.currentVideo.videoId) : -1;
const previousIndex = currentIndex <= 0 ? playlist.length - 1 : currentIndex - 1;
this.playVideoAtIndex(previousIndex);
}
playRandomVideo() {
if (!this.playlist.length) {
this.showMessage('Playlist is empty', 'info');
return;
}
const randomIndex = Math.floor(Math.random() * this.playlist.length);
this.playVideoAtIndex(randomIndex);
}
resumeStream() {
this.showMessage('Stream resumed', 'success');
}
pauseStream() {
this.showMessage('Stream paused', 'info');
}
stopStream() {
if (this.streamManager) {
this.streamManager.setCurrentVideo(null);
this.currentVideo = null;
this.updateCurrentVideoDisplay();
this.showMessage('Stream stopped', 'info');
}
}
restartCurrentVideo() {
if (this.currentVideo) {
this.showMessage('Restarting current video', 'info');
} else {
this.showMessage('No video is currently playing', 'info');
}
}
showMessage(text, type = 'info') {
const container = document.getElementById('messageContainer');
if (!container) return;
const message = document.createElement('div');
message.className = `message ${type}`;
message.innerHTML = `<strong>${text}</strong>`;
container.appendChild(message);
setTimeout(() => {
message.style.animation = 'slideOut 0.3s ease';
setTimeout(() => message.remove(), 300);
}, 3000);
}
escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
}
// Initialize stream admin
window.streamAdmin = new StreamAdmin();
</script>
<style>
@keyframes slideOut {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(400px);
opacity: 0;
}
}
</style>
</body>
</html>