16

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

Krt_Malta
  • 8,695
  • 17
  • 50
  • 89
  • look at this post: http://stackoverflow.com/questions/5703203/html5-video-change-multiple-sources nice and simple solution! –  Sep 19 '11 at 14:57

3 Answers3

24

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

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

Apple has a useful tutorial.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Phil Crosby
  • 449
  • 4
  • 8
5

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>
samccone
  • 9,746
  • 5
  • 39
  • 50
0

The property to be used:

videoTag.src

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

videoTag.play()
Delan Azabani
  • 73,106
  • 23
  • 158
  • 198