play multiple videos in a loop using HTML5 and JavaScript

I have been looking for a simple way of playing multiple videos in one video tag.
I have found a java script that is ment to work from

I also have a second script that dose the same but only plays the first video

Q1. The script only plays the first video the second video dose not play.

Q2. Is there any way to add more videos to the script lets say 4 videos in total.

Q3. If one of the videos is missing from the VIDEO folder would the script just move on to the next video or will it just stop working.

I know I asked 3 question and I am happy to start with only Question 1 thanks for any help given.....

Script as follows
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


  <video controls autoplay loop id="myVideo" >


<script type="text/javascript">
        var videoSource = new Array();



var videoCount = videoSource.length;

    function videoPlay(videoNum)

function myHandler() {
if(i == (videoCount-1)){
i = 0;



Open in new window

Second Different script
<title>video example</title>

    <video id="myVideo" height="400" width="400" autoplay onended="run();">   
        <source id="ss"  src="video/video1.mp4" type='video/mp4'>

        video_count =1;
        videoPlayer = document.getElementById("ss");        

        function run(){
            if (video_count == 4) video_count = 1;



Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:

You can use onended event of video control for this purpose. When this event fires you may trigger next video.

You may find following article very helpful in general:

Thanks and Regards

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paddy086Author Commented:
Hello Imran Javed Zia Thanks for your reply.
I Have been looking at your links could you help a little more with the scripts

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.