更改src和currentTime不能一起工作

更改src和currentTime不能一起工作

本文介绍了更改src和currentTime不能一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,问题是,对于我的应用程序,我必须动态更改视频src和currentTime。我试过独立改变两个工作正常。但是,当我尝试一起做这些时,有一些问题。

Well, the thing is, for my application, I have to change the video src and currentTime dynamically. I have tried changing both independently which worked fine. But, when I tried to do them together, there is some problem.

这是我的视频标签和一个按钮,点击哪个src和currentTime必须更改。

This is my video tag and a button, onclicking which src and currentTime must be changed.

<video id="video" src="sample.mp3" controls autoplay></video>
<button onclick="foobar()">change</button>

我的foobar()函数是

and my foobar() function is

function foobar()
{
v=document.getElementById("video");
v.src = "foo.mp3";
v.load();
v.currentTime = 3;
}

当我删除v.src或v.currentTime时,它工作正常。 ..
我尝试过使用networkState和currentState,没有运气。我甚至等了一段时间(javascript计时器)确保新mp3文件已完全加载,然后尝试更改currentTime。即使那样也行不通。

When I remove either v.src or v.currentTime, its working fine...I have tried using networkState and currentState, no luck. I have even waited for some time(javascript timers) made sure that the new mp3 file is completely loaded and then tried changing currentTime. Even that did not work.

请帮助我..

PS:我不想用任何第三方库。

PS: I don't want to use any third party libraries.

推荐答案

您可以使用网址设置计时器:

You may use the url to set the timer:

function foobar()
{
    v=document.getElementById("video");
    v.src = "foo.mp3#t=3";
    v.load();
}

它适用于这个小提琴

这篇关于更改src和currentTime不能一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 14:26