Page 1 of 1

Playing different movies with 1 script

PostPosted: Mon Feb 23, 2015 1:42 pm
by impulsmedia
Hello,
I try to set up a small app which starts playing different movies depending on the users selection. As "movie-preview" I use a still (preview_video1.png) shown in a picture object. Until now I realize the video-play-event after a click on my preview png in an iframe object which refers to a file with the code below. My simple (and my be stupid question...) is, how to fill the source tag <source src=".... URL" type="video/mp4"> with a var i.e. [SourceVideo], which is set on clicking my preview_videoX.png. Thanks for your help.

Code: Select all
<!DOCTYPE html>
<html>
<body>

<button onclick="playVid()" type="button">Play Video</button>
<button onclick="pauseVid()" type="button">Pause Video</button><br>

<video id="myVideo" width="320" height="176">
  <source src="http://www.myurl.de/videos/video1.mp4" type="video/mp4">
</video>

<script>
var vid = document.getElementById("myVideo");

function playVid() {
    myVideo.play();
}

function pauseVid() {
    myVideo.pause();
}

Re: Playing different movies with 1 script

PostPosted: Mon Feb 23, 2015 2:36 pm
by PaulTomo
Walter, This may help!

Not identical to your code but this worked for my test's with both images and mp3's.

First I parsed the list of titles and put the clips into an array, I then picked one of them at random and added just it's title from the split to a variable.

Code: Select all
SetVar [Clip] "[VideoSplit(2)]"


You need to add the HTML code to assign an ID, I put it on the button I was using as my click to start.

Code: Select all
<style>div {width: 330px; height: 250px;}</style><div id="myVideo"></div>


I then added some JS to the code area of the same button.

Code: Select all
BeginJS
document.getElementById("myVideo").src = 'http://MyWebSite/Video_Clips/'+$rootScope.Clip+'.mp4';
var myVideo = document.getElementById("myVideo");
myVideo.play();
EndJS


The bit that you are probably after is how you assign and to load the Video as a variable.
+$rootScope.Clip+'

This loads the [Clip] variable that was assigned from the split.

I just put all the code on the same click to start button.

Good luck.

Re: Playing different movies with 1 script

PostPosted: Tue Feb 24, 2015 1:21 am
by impulsmedia
Thank you, I´ll check this out asap.

Re: Playing different movies with 1 script

PostPosted: Tue Feb 24, 2015 11:02 am
by Neosoft Support
In the next update you will be able to change the contents of an iFrame object by using a variable as the source property.