-
Notifications
You must be signed in to change notification settings - Fork 12
/
script.js
87 lines (79 loc) · 2.25 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
const channels = document.querySelectorAll('.channel-card');
const playerContainer = document.getElementById('video-player');
const player = document.getElementById('player');
let currentIndex = 0;
// Função para atualizar o foco no card ativo
const updateFocus = () => {
channels.forEach((channel, index) => {
channel.classList.toggle('active', index === currentIndex);
});
channels[currentIndex].focus();
};
// Função para reproduzir o canal selecionado
const playChannel = () => {
const channelUrl = channels[currentIndex].getAttribute('data-url');
if (Hls.isSupported()) {
const hls = new Hls();
hls.loadSource(channelUrl);
hls.attachMedia(player);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
player.play();
});
} else if (player.canPlayType('application/vnd.apple.mpegurl')) {
player.src = channelUrl;
player.addEventListener('loadedmetadata', () => {
player.play();
});
} else {
alert("Seu dispositivo não suporta reprodução HLS.");
}
playerContainer.style.display = 'flex';
};
// Função para navegar pelos canais
const navigateChannels = (direction) => {
currentIndex = (currentIndex + direction + channels.length) % channels.length;
updateFocus();
playChannel();
};
// Função para fechar o player de vídeo
const closePlayer = () => {
playerContainer.style.display = 'none';
player.pause();
};
// Inicialização
updateFocus();
playChannel();
// Evento para navegar pelos canais
document.addEventListener('keydown', (event) => {
switch (event.key) {
case 'ArrowUp':
navigateChannels(1);
break;
case 'ArrowDown':
navigateChannels(-1);
break;
case 'ArrowRight':
currentIndex = (currentIndex + 1) % channels.length;
updateFocus();
break;
case 'ArrowLeft':
currentIndex = (currentIndex - 1 + channels.length) % channels.length;
updateFocus();
break;
case 'Enter':
playChannel();
break;
case 'GoBack':
case 'Escape':
if (playerContainer.style.display === 'flex') {
closePlayer();
} else {
webOS.platformBack();
}
break;
default:
break;
}
});
// Fechar o player de vídeo ao sair do modo de tela cheia
player.addEventListener('ended', closePlayer);