当我在JS中使用动态源作为音频src时音频CurrentTime不起作用?

时间:2016-01-19 15:36:03

标签: javascript php audio html5-audio

我什么时候把时间游侠放在特定的时间音频停止(这是在我把动态网址放到实际的mp3文件网址之后发生的)

这是我的JS音频播放器的代码

    <!DOCTYPE html>
<html>
<head>
    <title></title>
</head>

<body>

    <button id="pp" onclick="cpp()">Play</button>
    <input id="playControl" type="range" oninput="cplayback(this.value)" min="0" max="100" value="0">
    <button id="mp" onclick="cmp()">Mute</button>
    <input id="volumeControl" type="range" oninput="cvolume(this.value)" min="0" max="100" value="50">
    <p id="bulala"></p>


</body>
</html>

<script type="text/javascript">
    var audio=new Audio();

    audio.src="http://localhost/tuniPlayer/test.php";

    function cpp(){
        if (audio.paused) {
            audio.play();
            audio.volume=document.getElementById('volumeControl').value/100;
            document.getElementById('pp').innerHTML="Pause";
        }else{
            audio.pause();
            document.getElementById('pp').innerHTML="Play";
        }
    }

    function cmp(){

        if(audio.muted){
            audio.muted=false;
            document.getElementById('mp').innerHTML="Mute";
        }else{
            audio.muted=true;
            document.getElementById('mp').innerHTML="unmute";
        }
    }

    function cvolume(v){

        audio.volume=v/100;
    }

    function cplayback(t){

        audio.currentTime=(t/100)*audio.duration;


    }


setInterval(function(){
    document.getElementById("playControl").value=(audio.currentTime*100)/audio.duration;
    document.getElementById("bulala").innerHTML=(audio.currentTime/100).toFixed(2) +"/"+(audio.duration/100).toFixed(2);
    if(audio.currentTime==audio.duration){

        document.getElementById("pp").click();
        document.getElementById("pp").click();
    }
}, 200);




</script>

和php代码。我已经搜索了许多解决方案,包括缓冲区和一些库,以了解他们是如何做到的。但到目前为止没有运气

&#39;

    $file="audio/1.mp3";

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: inline; filename="'.basename($file).'"');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);

    exit;
 ?>'

0 个答案:

没有答案