我有五个可能播放视频的视频,以及一系列名为activeVideos的活动视频。当一个视频完成播放时,我需要获取其索引,在activeVideos数组中找到它的位置,并获取数组中的下一个值。如果数组中没有更多值,我需要获取第一个值。基本上是这样的:
activeVideos = [0,1,3]
videos = [video1, video2, video3];
function nextVideo(e:Event){
var curIndex = videos.indexOf(currentVideo);
var next = activeVideos.find(curIndex).nextValue // pseudo-code - need to locate the position of the current video within the active array, select the next element, and call show video.
showVideo(videos[next]);
}
我该怎么做?
答案 0 :(得分:1)
activeVideos = [0,1,3]
videos = [video1, video2, null, video3];
function nextVideo(e:Event){
var curIndex = videos.indexOf(currentVideo);
var next = activeVideos[curIndex+1] || activeVideos[0];
showVideo(videos[next]);
}
答案 1 :(得分:0)
也许你可以在家里试试这个,我必须承认我的闪光灯可能会因为html5,css3 + js大肆宣传而有点生锈:)
nextIndex = -1;
nextIndex = ( (curIndex+1 == videos.length) ? 0 : curIndex+1 );
if (nextIndex > -1){
var next = activeVideos[nextIndex];
// ... do your stuff
}
答案 2 :(得分:0)
function nextVideo(e:Event){
var curIndex = videos.indexOf(currentVideo) + 1;
var nextVideo = curIndex >= videos.length ? videos[0] : videos[curIndex];
showVideo(nextVideo);
}