HTML5音频播放器:暂停不起作用

时间:2013-09-12 09:46:46

标签: jquery html5 audio

你可以帮我这个代码吗?我正在创建一个音频播放器,这是我的代码:

$(document).ready(function () {
  $("#play").bind("click", function () {
    $("#audio-player")[0].play();
    $(this).attr('id', 'pause-bt');
  })

  $("#pause-bt").live({
    click: function () {
        $("#audio-player")[0].pause();
        $(this).attr('id', 'play');
    }
  })
})

我正在使用jquery live和bind,但它们都不起作用。

请帮帮我。

由于

3 个答案:

答案 0 :(得分:1)

如果你想使用HTML5,我建议使用HTML5音频标签。它会在浏览器中为您提供播放器。赫比我附上了这个小提琴。

HTML5音频播放器(jsfiddle.net/L5wRh/126 /)

感谢。

答案 1 :(得分:1)

感谢Omar:https://stackoverflow.com/users/1771795/omar

Omar解决的代码

<script type="text/javascript">
    $(document).ready(function () { 
       $(document).on("click", '#play', function () { $("#audio-player")[0].play(); $(this).attr('id', 'pause-bt'); }); 
       $(document).on('click', '#pause-bt', function () { $("#audio-player")[0].pause(); $(this).attr('id', 'play'); }); 
    });
</script>

问题突然......

答案 2 :(得分:0)

这对我有用

$(document).ready(function(){
  $('.stop').on('click', function(){
    document.getElementById("videocontainer").pause();  
  });
});
 <video id="videocontainer" width="320" height="240" controls>
  <source src="vid/Kuwait_City.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
</video> 

<a href="#" class="stop">stop</a>

相关问题