我在阵列中有一个视频播放列表。我想在选择的视频/视频播放时调用一个功能(例如警告"注意!")(例如2ed,4th,8th ......)。任何解决方案都很受欢使用完整的code from my JSfiddle。
var videoSource = new Array();
videoSource[0]='';
videoSource[2]='';
videoSource[3]='';
videoSource[4]='';
videoSource[5]='';
var i = 0;
var videoCount = videoSource.length;
document.getElementById("myVideo").setAttribute("src",videoSource[0]);
videoPlay(0);
function videoPlay(videoNum)
{
document.getElementById("myVideo").setAttribute("src",videoSource[videoNum]);
document.getElementById("myVideo").load();
document.getElementById("myVideo").play();
}
document.getElementById('myVideo').addEventListener('ended',myHandler,false);
function myHandler() {
i++;
if(i == (videoCount)){ i = 0; videoPlay(i);}
else{videoPlay(i);}
}
答案 0 :(得分:1)
由于视频开始播放时代码未被阻止,因此可以在调用play
后立即放置逻辑。
检查索引的最简单方法是类似if(index==1 || index == 3 || index == 4)
等,但更可维护的是将其保留在数组中,例如:if([1,3,4].indexOf(vidIndex) != -1)
。该数组包含索引。 indexOf
返回数组内的索引,如果数组中的不是,则返回-1
使用提醒的示例:Fiddle
更高级的用例,将存储url的内部对象,您可以在其中为对象分配特定的元数据和行为。例如:Fiddle with objects
答案 1 :(得分:0)
您可以在#!/usr/bin/env python
#coding:utf-8
import re
f= open('file','r')
for line in f:
data = line.replace("cat","").replace("dog","")
if len(data) != 1:
print data
元素上收听playing
事件。以下是如何做到这一点:
video
启动视频时将调用document.getElementById('myVideo').addEventListener("playing", play_started, false);
方法。在该方法中,您可以检查是否正在播放特定视频。希望这会有所帮助。
答案 2 :(得分:0)
想法是添加下拉列表:
const videoSources =[
'http://mdn.github.io/learning-area/html/multimedia-and-embedding/video-and-audio-content/rabbit320.webm',
'http://media.w3.org/2010/05/sintel/trailer.mp4',
'https://vtt.tumblr.com/tumblr_ok41s7Iebh1t4fjz0_480.mp4', 'https://vtt.tumblr.com/tumblr_ok44bpZZka1t4fjz0_480.mp4','http://media.w3.org/2010/05/bunny/trailer.mp4'
];
const select = document.querySelector('select');
select.onchange = function() {
videoPlay(parseInt(this.value))
};
videoSources.forEach(appendOption);
function appendOption(url, index) {
const option = document.createElement("option");
option.setAttribute("value", index);
option.innerHTML = url.substr(url.lastIndexOf('/')+1);
select.appendChild(option);
}
var i = 0;
var videoCount = videoSources.length;
document.getElementById("myVideo").setAttribute("src",videoSources[0]);
videoPlay(0);
function videoPlay(videoNum)
{
document.getElementById("myVideo").setAttribute("src",videoSources[videoNum]);
document.getElementById("myVideo").load();
document.getElementById("myVideo").play();
}
<div>
<select onchange="videoPlay(parseInt(this.value))">
</select>
</div>
<video class="myVideo" controls autoplay muted id="myVideo">
https://jsfiddle.net/nojava/5vo8cdbr/#run</video>