HTML5 视频:识别新来源
我正在尝试创建一个 HTML5 视频播放器,该播放器将在当前视频结束后自动播放新视频。
这是到目前为止我当前的代码(http://jsfiddle.net/fFuez/1/):
<video autobuffer controls width="500" id="player">
<source src="http://nettuts.s3.amazonaws.com/763_sammyJSIntro/trailer_test.mp4" type="video/mp4" id="source">
</video>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready( function () {
$("#player").bind("ended", function() {
alert("Finshed, play new video now...");
$('#source').attr('src', 'http://video-js.zencoder.com/oceans-clip.mp4');
});
});
</script>
已结束的事件正在触发(根据 alert();
),但新文件似乎无法被播放器识别。
I'm attempting to create a HTML5 video player that will play a new video automatically once the current video has ended.
Here is my current code so far (http://jsfiddle.net/fFuez/1/):
<video autobuffer controls width="500" id="player">
<source src="http://nettuts.s3.amazonaws.com/763_sammyJSIntro/trailer_test.mp4" type="video/mp4" id="source">
</video>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready( function () {
$("#player").bind("ended", function() {
alert("Finshed, play new video now...");
$('#source').attr('src', 'http://video-js.zencoder.com/oceans-clip.mp4');
});
});
</script>
The ended event is firing (according to the alert();
) but the new file does't seem to be recognized by the player.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除
元素并直接在
标记上添加
src
属性。当有多个源时,您只需要元素。然后,更改
的
src
,它应该可以正常工作。如果您需要支持更多文件类型(例如,Firefox 的 OGG 视频),那么您应该使用
canPlayType()
方法来检测需要哪个src
扩展名。Remove the
<source>
element and add thesrc
attribute directly on the<video>
tag. You only need<source>
elements when there are more than one source. Then, change thesrc
of the<video>
and it should work just fine.If you need to support more filetypes (OGG video for Firefox, for example), then you should use the
canPlayType()
method to detect whichsrc
extension is needed.您需要使用
#player
,而不是#source
You need to use
#player
, not#source