通过使用< video>在Chrome中依次播放两个视频标签 [英] PLaying two videos in sequence in Chrome by using the <video> tag

查看:99
本文介绍了通过使用< video>在Chrome中依次播放两个视频标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在HTML5视频标签中按顺序播放两个视频?

How do I play two videos in a sequence in the HTML5 video tag?

在Google Chrome浏览器中,以下代码仅播放第一个介绍性视频.

In Google Chrome, the following code plays only the first intro video.

<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script>

var i = 0;
var sources = ['1.mp4', '2.mp4'];
videoElement.addEventListener('ended', function(){
   videoElement.src = sources[(++i)%sources.length];
   videoElement.load();
   videoElement.play();
}, true);

</script>

</head>
<body>
<video id="videoElement" width="640" height="360" autoplay="autoplay">
    <source src="intro.mp4" type="video/mp4"></source>
</video>

<body>
<html>

推荐答案

浏览器应使用JavaScript代码触发错误未定义videoElement",您必须从DOM获取视频元素,而不是直接使用其ID.请将您的代码更改为

Browser should fire error 'videoElement is not defined' with your JavaScript code, you must get video element from DOM instead of using its id directly. Please change your code to

$(document).ready(function() {
    //place code inside jQuery ready event handler 
    //to ensure videoElement is available
    var i = 0;
    var sources = ['1.mp4', '2.mp4'];
    $('#videoElement').bind('ended', function() {
        //'this' is the DOM video element
        this.src = sources[i++ % sources.length];
        this.load();
        this.play();
    });
});

这篇关于通过使用&lt; video&gt;在Chrome中依次播放两个视频标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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