Setting the currentTime of an <audio> tag not working?

前端 未结 6 666
生来不讨喜
生来不讨喜 2020-12-31 07:41

I have this audio tag playing in the background, and I\'m able to store the progress in seconds to a cookie. But in no way I\'m able to start the audio from that cookie. (fo

6条回答
  •  忘掉有多难
    2020-12-31 08:09

    You need to wait until audio source loads before you set the current time.

    $(function(){
        $('audio').bind('canplay', function(){
            $(this)[0].currentTime = $.cookie('audioTime');
        });
    });
    

提交回复
热议问题