txtorg commited on
Commit
02f2f15
·
verified ·
1 Parent(s): 36a2f29

Create script.js

Browse files
Files changed (1) hide show
  1. public/script.js +56 -0
public/script.js ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function changeChannel(channel) {
2
+ document.getElementById("channelName").textContent = `Channel ${channel}`;
3
+ document.getElementById("currentShow").textContent = `Now Playing: Loading...`;
4
+
5
+ const video = document.getElementById("tvPlayer");
6
+ const streamUrl = `/hls/${channel}/index.m3u8`;
7
+
8
+ if (Hls.isSupported()) {
9
+ const hls = new Hls();
10
+ hls.loadSource(streamUrl);
11
+ hls.attachMedia(video);
12
+ hls.on(Hls.Events.MANIFEST_PARSED, () => {
13
+ video.play();
14
+ document.getElementById("currentShow").textContent = `Now Playing: Channel ${channel}`;
15
+ });
16
+ } else if (video.canPlayType("application/vnd.apple.mpegurl")) {
17
+ video.src = streamUrl;
18
+ video.addEventListener("loadedmetadata", () => {
19
+ video.play();
20
+ document.getElementById("currentShow").textContent = `Now Playing: Channel ${channel}`;
21
+ });
22
+ }
23
+ }
24
+
25
+ function togglePlay() {
26
+ const video = document.getElementById("tvPlayer");
27
+ if (video.paused) {
28
+ video.play();
29
+ } else {
30
+ video.pause();
31
+ }
32
+ }
33
+
34
+ function toggleFullscreen() {
35
+ const video = document.getElementById("tvPlayer");
36
+ if (video.requestFullscreen) {
37
+ video.requestFullscreen();
38
+ } else if (video.mozRequestFullScreen) {
39
+ video.mozRequestFullScreen();
40
+ } else if (video.webkitRequestFullscreen) {
41
+ video.webkitRequestFullscreen();
42
+ } else if (video.msRequestFullscreen) {
43
+ video.msRequestFullscreen();
44
+ }
45
+ }
46
+
47
+ function toggleMute() {
48
+ const video = document.getElementById("tvPlayer");
49
+ video.muted = !video.muted;
50
+ document.getElementById("muteBtn").textContent = video.muted ? "🔇 Unmute" : "🔊 Mute";
51
+ }
52
+
53
+ // Set default channel on page load
54
+ window.onload = () => {
55
+ changeChannel(1);
56
+ };