HTML audio can't set currentTime

后端 未结 8 920
予麋鹿
予麋鹿 2020-11-30 05:22

I am using Chrome. In my dev tools console, I tried the following:

Everything works as expected except last line. Why can\'t I set currentTime

8条回答
  •  醉梦人生
    2020-11-30 06:18

    You need to do something like this (if you use jQuery)

    $('#elem_audio').bind('canplay', function() {
      this.currentTime = 10;
    });
    

    or in Javascript

    var aud = document.getElementById("elem_audio");
    aud.oncanplay = function() {
        aud.currentTime = 10;
    };
    

    The reason behind for this setup is you need to make sure the audio is ready to play.

提交回复
热议问题