停止网络电台播放器

时间:2013-05-10 22:51:04

标签: jquery html5 audio

我为网络电台制作了一个自定义音频播放器。问题是我无法找到一种方法来阻止它。如果暂停,则恢复音频将从已暂停的点继续播放。因此,如果您暂停播放器,当您恢复播放时,您会听到暂停播放的歌曲,但流服务器已播放下一曲目。换句话说,如果你暂停并稍后恢复,你就不在这里流服务器现在播放的内容。在搜索网络后,我发现我必须停止播放器和NT RESUME。任何人都知道如何实现这一目标?另一种选择是使用FLASH PLAYER,但我真的需要使用自定义播放器而不知道如何在flash中进行操作。

这是我的代码:

PLAYER.JS

var audio = document.getElementById("audio");
audio.controls = false;
audio.addEventListener('play', function() {
                var playpause = document.getElementById("playpause");
                playpause.title = "pause";
                playpause.innerHTML = "pause";
            }, false);
            audio.addEventListener('pause', function() {
                var playpause = document.getElementById("playpause");
                playpause.title = "play";
                playpause.innerHTML = "play";
            }, false);
            audio.addEventListener("ended", function() { this.pause(); }, false);           


            function togglePlayPause() {

                var playpause = document.getElementById("playpause");

                if (audio.paused || audio.ended) {
                    // Change the title and the text of the button to "pause"
                    playpause.title = "pause";
                    playpause.innerHTML = "pause";

                    audio.play();
                }

                else {

                    playpause.title = "play";
                    playpause.innerHTML = "play";

                    audio.pause();
                }
            }


            function setVolume() {

                var volume = document.getElementById("volume");
                audio.volume = volume.value;
            }


            function toggleMute() {
                audio.muted = !audio.muted;

                if (audio.muted) {
                    mute.title="muted"
                } else {
                    mute.title="notmuted"
                }
            }

HTML MARKUP

<audio id="audio">
    <source src="http://xxx.xxx.com:xxxx/stream" type="audio/mp3">
</audio>
<div id="controls">             
    <button id="playpause" title="play" onclick="togglePlayPause()">Play</button>
    <input id="volume" min="0" max="1" step="0.01" type="range" onchange="setVolume()" /> 
    <button id="mute" onclick="toggleMute()" title="notmuted">Mute</button> 
</div>

0 个答案:

没有答案