What is the best method to use to have multiple videos (mp4) able to play, like this:
[Play video 1] … [Play video 2] … [Play video 3]
I have tried using 3 scenes, then the same 3 buttons on each scene to play the video via javascript, however it is very clunky and buggy. hypeDocument.getElementById(‘video1’).play();
Have a search for video on the site. There are plenty of examples using a few methods, including using a single video element and load each video into that when needed.
More about video tags here.
More about the HTML Video DOM here.
Important: In the JavaScript that follows below we will be using the ID of the video tag itself (“videoHolder”) - not Hype’s “Unique Element ID” field in the “Identity Inspector”.
The buttons labeled “Video 1” & “Video 2” do not have a pause function, they just play. They have IDs that match the video name… e.g. the “Video 1” button’s ID is “video_01” and the video it will play is “video_01.mp4”. In the JavaScript below we will add the “.mp4” to the button’s ID to yield the full name of the video.
Clicking on one of these buttons triggers the “vidSelectPlay()” function:
var vid = document.getElementById("videoHolder");
var whichVid = element.id; // the ID of the button that was clicked
vid.src = "${resourcesFolderName}/" + whichVid + ".mp4";
vid.play();
@JimScott scot has given you most of it for what you say you want.
For the
When it reaches the end, it returns to the (looping) main menu
Look at the HTML Video DOM link he supplied there you will find HTML Audio/Video Events in particular ended
Each event listed has examples when you click them.
There are also examples on the forum if you search..
I ended up doing it in the GUI, manual way using scenes. I only have very little experience with html and css. Javascript is beyond me. Archive.zip (2.1 MB)
I assume by buggy you mean that the scene may go back to the menu before the video is fully complete?
In Javascript, HTML5 <video> elements have an onended callback that will get triggered when the video is done playing. You can utilize this for each scene by:
First, remove your existing Jump to Scene actions
Select the video and give it a Unique Element ID in the Identity Inspector like vid1 or something.
In the Scene Inspector add an On Scene Load action for each scene that is set to Run Javascript. The code would just look like: