Krt_Malta
Krt_Malta

Reputation: 9465

Change video being played in HTML5 video

I'm using the tags in HTML5 to play a video on a web browser... (and I'm very impressed with this new feature)

Is there the functionality to change the video being played through Javascript? Say when I select another video from a list, a Javascript function would be called which would contain something on the lines of MyVideo.VideoLocation = //location of new video to be played. Is this possible please?

Thanks and regards, Krt_Malta

Upvotes: 16

Views: 25841

Answers (3)

Phil Crosby
Phil Crosby

Reputation: 449

Webkit requires that you call "load()" after changing the source:

videoTag.src = "newVideo";
videoTag.load();
videoTag.play();

Apple has a useful tutorial.

Upvotes: 24

samccone
samccone

Reputation: 10926

Here is the solution, tested on Ipad/Iphone/Webkit/Firefox

<script>

function playNext(path,target)
{
target[0].src=path;
target[0].load();
target[0].play();
}

playNext("pathToMovie",$('#video_1'));

</script>

Upvotes: 5

Delan Azabani
Delan Azabani

Reputation: 81384

The property to be used:

videoTag.src

If it doesn't auto-start playing after that:

videoTag.play()

Upvotes: 0

Related Questions