设置& lt; audio& gt;的currentTime.标签不起作用? [英] Setting the currentTime of an <audio> tag not working?

查看:69
本文介绍了设置& lt; audio& gt;的currentTime.标签不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在后台播放此音频标签,并且可以将进度以秒为单位存储到Cookie中.但是,我绝对无法从该Cookie中启动音频.(用于在其他页面上继续)

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. (for continuing on other pages)

$("p#sound audio").currentTime = $.cookie("audioTime");

<audio autoplay="autoplay" loop="loop" ontimeupdate="document.getElementById('tracktime').innerHTML = Math.floor(this.currentTime); $.cookie('audioTime', Math.floor(this.currentTime));">
    <source src="audio/song.ogg" type="audio/ogg" />
    <source src="audio/song.mp3" type="audio/mp3" />
    Your browser does not support the audio tag.
</audio>
<span id="tracktime">0</span>

这与从头开始重新加载歌曲有关吗?

Does this have to do with the song being loaded again from start?

谢谢!

$("p#sound audio").get[0].currentTime

使用.get [0]也不起作用.

With .get[0], it doesn't work either.

有人可以帮我清理一下吗?非常感谢!

Can someone please clear things up for me? Greatly appreciated!

推荐答案

在设置当前时间之前,您需要等到 audio 源加载完毕.

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

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

这篇关于设置&amp; lt; audio&amp; gt;的currentTime.标签不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆