File size: 2,552 Bytes
f7f4c16
 
 
daf05bf
f7f4c16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
document.addEventListener('DOMContentLoaded', function () {
    // Proxy URL to bypass CORS policy
    const proxyURL = 'https://api.allorigins.win/get?url=';
    const playlistURL = 'h';
    const proxyPlaylistURL = proxyURL + encodeURIComponent(playlistURL);

    fetch(proxyPlaylistURL)
        .then(response => response.json())
        .then(data => {
            const playlistContent = data.contents;
            const playlist = document.getElementById('playlist');
            const lines = playlistContent.split('\n');
            let firstStreamUrl = null;
            lines.forEach((line, index) => {
                if (line.startsWith('#EXTINF')) {
                    const title = line.split(',')[1];
                    const url = lines[index + 1].trim();
                    const listItem = document.createElement('li');
                    listItem.className = 'list-group-item';
                    listItem.innerHTML = `<a href="#" data-url="${url}">${title}</a>`;
                    playlist.appendChild(listItem);
                    
                    // Set the first stream URL
                    if (firstStreamUrl === null) {
                        firstStreamUrl = url;
                    }
                }
            });

            // Play the first stream by default
            if (firstStreamUrl !== null) {
                playStream(firstStreamUrl);
            }

            playlist.addEventListener('click', function (event) {
                event.preventDefault();
                if (event.target && event.target.nodeName === 'A') {
                    const streamUrl = event.target.getAttribute('data-url');
                    playStream(streamUrl);
                }
            });

            // Hide the loading screen after at least 1 second
            setTimeout(function () {
                document.getElementById('loading-screen').style.display = 'none';
                document.getElementById('content').style.display = 'block';
            }, 1800); // 1800 milliseconds = 1 second
        })
        .catch(error => console.error('Error fetching the playlist:', error));

    // Create a single instance of the player
    const playerElement = document.getElementById('player');
    const player = new Clappr.Player({
        parentId: "#player",
        width: '100%',
        height: '100%',
        autoPlay: true,
        mediacontrol: {seekbar: "#bb86fc", buttons: "#e0e0e0"},
        mute: false,
    });

    function playStream(url) {
        player.load(url);
    }
});