HTML audio can't set currentTime

后端 未结 8 840
予麋鹿
予麋鹿 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:25

    I had the same problem, and the reason was missing headers on the mp3 file, like:

    Content-Length, Content-Range, Content-Type

    0 讨论(0)
  • 2020-11-30 06:29

    Why cant I set currentTime on it?

    Could not reproduce currentTime being set to 0 after setting to 10. Is 18.mp3 duration less than 10?

    var request = new XMLHttpRequest();
    request.open("GET", "/assets/audio/18.mp3", true);
    request.responseType = "blob";    
    request.onload = function() {
      if (this.status == 200) {
        var audio = new Audio(URL.createObjectURL(this.response));
        audio.load();
        audio.currentTime = 10;
        audio.play();
      }
    }
    request.send();
    

    jsfiddle http://jsfiddle.net/Lg5L4qso/3/

    0 讨论(0)
提交回复
热议问题