0

我为网络收音机构建了一个自定义音频播放器。问题是我找不到阻止它的方法。如果暂停,则当恢复时,音频会从暂停点继续播放。因此,如果您暂停播放器,当您恢复播放器时,您会听到暂停播放器的歌曲,但流服务器已经播放了下一首曲目。换句话说,如果您稍后暂停并恢复,您不会在此处播放流服务器现在播放的内容。在网上搜索后,我发现我必须停止播放器和 NT RESUME。任何人都知道有什么方法可以实现吗?另一种选择是使用 FLASH PLAYER 但我真的需要使用自定义播放器并且不知道如何在 Flash 中做到这一点。

这是我的代码:

播放器.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 标记

<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>
4

0 回答 0