-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
138 lines (120 loc) · 2.75 KB
/
app.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
/**
* A remote control key variables
*/
let RC_LEFT,RC_UP,RC_RIGHT,RC_DOWN,RC_ENTER,RC_BACK,RC_EXIT;
let channel = 0
let hls_source = 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8';
/**
* The root html element
*/
let root = null;
/**
* Function for creating the application and getting it ready for the users to use
*/
function createApp() {
console.log("Creating the app...");
registerKeys();
console.log("Initializing HLS...");
playVideo();
/**
* Setting the root HTML element
*/
root = document.getElementById("app");
document.addEventListener("keydown", handleKeyPress);
/**
* Here you can start doing awesome things!
*/
console.log("...and it's ready for use");
}
function playVideo(){
var video = document.getElementById('video');
if (Hls.isSupported()) {
var hls = new Hls({
debug: true,
});
console.log("Init hls successful");
hls.loadSource(hls_source);
hls.attachMedia(video);
hls.on(Hls.Events.MEDIA_ATTACHED, function () {
video.muted = true;
video.play();
});
console.log("Video played successful");
}
}
/**
* Setting key event numeric value to variables, so you don't have to numeric values
*/
function registerKeys() {
console.log("registerKeys is called");
RC_LEFT = 37;
RC_UP = 38;
RC_RIGHT = 39;
RC_DOWN = 40;
RC_ENTER = 13;
RC_BACK = 10009;
RC_EXIT = 10182;
}
/**
* Function which is called when a key is pressed
*/
function handleKeyPress(event) {
switch(event.keyCode) {
case RC_ENTER:
selectItem();
break;
case RC_EXIT:
break;
case RC_LEFT:
keyPressLeft();
break;
case RC_RIGHT:
keyPressRight();
break;
case RC_UP:
keyPressUp();
break;
case RC_DOWN:
keyPressDown();
break;
default:
console.log("You need to add some cases here, a key you pressed was", event.keyCode);
}
}
/**
* The key press functions
*/
function keyPressUp() {
console.log("You pressed the up key");
// root.innerHTML = "UP";
nextChannel()
}
function keyPressDown() {
console.log("You pressed the down key");
// root.innerHTML = "DOWN";
previousChannel()
}
function keyPressLeft() {
console.log("You pressed the left key");
// root.innerHTML = "LEFT";
}
function keyPressRight() {
console.log("You pressed the right key");
// root.innerHTML = "RIGHT";
}
function selectItem() {
console.log("You pressed the enter key");
// root.innerHTML = "ENTER";
}
function nextChannel() {
if (channel !== 0) return;
hls_source = 'https://test-streams.mux.dev/tos_ismc/main.m3u8';
channel = 1;
playVideo()
}
function previousChannel() {
if (channel !== 1) return;
hls_source = 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8';
channel = 0;
playVideo()
}