Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change video being played in HTML5 video

Tags:

html

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

like image 568
Krt_Malta Avatar asked May 05 '10 10:05

Krt_Malta


People also ask

How do I make videos play automatically in HTML5?

Try autoplay="autoplay" instead of the "true" value. That's the documented way to enable autoplay.

How do I change the src of a video tag?

To change source on HTML5 video tag with JavaScript, we an set the src property of the video element. const changeSource = (url) => { const video = document. getElementById("video"); video. src = url; video.


2 Answers

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

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

Apple has a useful tutorial.

like image 133
Phil Crosby Avatar answered Oct 17 '22 08:10

Phil Crosby


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>
like image 28
samccone Avatar answered Oct 17 '22 07:10

samccone