本文介绍了在“已结束”的阵列中播放下一个视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一系列视频,当一个结束时,数组中的下一个应该播放。 我找到了这个脚本:I have an array of videos, and when one ends, the next in the array should play.I've found this script:function myNewSrc() { var myVideo = document.getElementsByTagName("video")[0]; myVideo.src = "http://cheerioscoupons.info/wp-content/uploads/_Cheerios-Coupons-1-300x283.jpg"; myVideo.load(); myVideo.play();}function myAddListener(){ var myVideo = document.getElementsByTagName("video")[0]; myVideo.addEventListener('ended',myNewSrc,false);}但我在当前脚本中实现它时遇到了麻烦, but I'm having trouble implementing it in my current script, which is,var numb = $(this).index(), videos = [ "images/talking1.m4v", "images/talking2.m4v", "images/talking1.m4v", "images/talking2.m4v", "images/talking1.m4v", "images/talking2.m4v" ], myVideo = document.getElementById("myVid"); myVideo.src = videos[numb]; myVideo.load(); setTimeout(function(){ myVideo.play(); }, 200);所以,有两个问题: 他们在干涉吗?第一个根本不会改变视频。 如何组合这些视频,以便下一个被调用的视频是数组中的下一个? 推荐答案 1。 document.getElementsByTagName 将返回一个元素数组,而不是一个。所以1. document.getElementsByTagName will return an array of elements, not one. Sovar myVideo = document.getElementsByTagName("video");myVideo.addEventListener('ended',myNewSrc,false); //wrongvar myVideo = document.getElementsByTagName("video");myVideo.load(); //wrongmyVideo.play(); //wrong应该是什么:myVideo[0].load() //if there is only onefor(var i=0;i<myVideo.length;i++){ myVideo[i].load(); //if there is more} 2。 在结束后播放另一个视频,var videos = [ "images/talking1.m4v", "images/talking2.m4v",];function playArray(index,ele,array,listener){ ele.removeEventListener(listener||0); ele.src = array[index]; ele.load(); ele.play(); index++; if(index>=array.length){ index=0; } listener = ele.addEventListener('ended',function(){ playArray(index,ele,array,listener); },false);}playArray(0,document.getElementById("myVid"),videos); LIVE DEMO: http://jsfiddle.net/DerekL/qeLcD/ (替换为带有文本而不是viedos的数组)LIVE DEMO: http://jsfiddle.net/DerekL/qeLcD/ (Replaced with an array with text instead of viedos) 这篇关于在“已结束”的阵列中播放下一个视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-19 02:00