window.onload=function() { soundManager.setup({ url: "/swf/", preferFlash: false, onready: function() { window.soundPlayer = soundManager.createSound({ id: 'radio', url: 'http://91.121.59.45:8089/stream', stream: true, autoPlay: false, usePolicyFile: true, preferFlash: false, autoStart: false }) var playButton = document.getElementById("state"); playButton.onclick = function() { if (window.playerPlaying) { console.log("should stop") window.soundPlayer.stop(); window.playerPlaying = false; playButton.innerHTML = "▶"; } else { console.log("should start"); window.soundPlayer.start(); window.playerPlaying = true; playButton.innerHTML = "⏸"; } } }, ontimeout: function() { console.log("soundmanager timeout") } }); window.evtSource = new EventSource("/api/icecast.sse"); window.icecastStats = {}; window.evtSource.addEventListener('icecast', function(e) { var data = JSON.parse(e.data).icecast; document.getElementById("np").innerHTML = data.np; document.getElementById("genre").innerHTML = data.genre + " en direct"; player = document.getElementById("player"); if (data.live != window.icecastStats.live) { if (data.live) { player.classList = ["live"]; console.log("is live"); } else { player.classList = ["autodj"]; console.log("stopped live"); } } window.icecastStats = data; }, false); }