设置< audio>的currentTime标记不起作用? [英] Setting the currentTime of an <audio> tag not working?

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

问题描述

我在后台播放了这个音频标签,并且我可以在几秒钟内将进度存储到cookie中。
但我绝不能从该cookie启动音频。 (用于在其他页面上继续)

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

这是否与从开始重新加载的歌曲有关?



谢谢!

编辑:

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

使用.get [ 0],它也不起作用。



有人可以为我清理一些东西吗?非常感谢!

解决方案

您需要等到音频你设置当前时间。

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


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?

Thanks!

EDIT:

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

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

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

解决方案

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

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

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

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