Using ExternalInterface to change videos with video.Maru
November 15th, 2007 . by polyGeekWould you like to play Flash videos on your site and have links to play various different videos in your HTML code?
Here’s how to do it using the Flash player’s External Interface as a bridge between Javascript and Actionscript, which then uses the video.Maru API to switch videos.
Download source here, 1.2 megs with videos.
Here’s what the Actionscript code looks like:
Take a look at the first line of code: System.security.allowDomain(’http://videomaru.com/’). You’ll have to edit that to make it work on your machine. And give the System.security docs a read if you have any problems. I got everything to work by just opening the .htm file locally but that’s not always the case. Sometimes the ExternalInterface doesn’t work unless you are using a hosted file. I’ve wasted many an hour trying to debug when forgetting that little nugget.
And this is all there is to the Javascript:








Can the fullscreen option work with The ExternalInterface option?
What I would really like to do is have a page with various links in it that causes a pop up window that shows the proper video depending on what link they click on. Is there anywhere I can get information on doing that.
Thanks,
Matt
@Matt, what you probably want to do is use FlashVars for that. Your links would just open a unique popup window as usual. Each popup window would load the same SWF/videoPlayer. In the
Does that work for you?
Thank You… I hope this works… one more question.
The menu on fullscreen mode can you get it so that it does not expand with the screen.
Thanks
Matt
@Matt, I’ll look into what you can and cannot do with Fullscreen and write a tutorial about it. My understanding is that Fullscreen just scales everything up. But there might be some API calls that I could add that would scale things back again. We’ll see.
Hi Dan,
I’ve worked with this and it works great. There is however a small issue:
If you pause or stop a video that is currently playing and then click a link to load another video, the play/pause toogle isn’t reset.
I’ve tried playing with the AS and got it a little better:
function playVideo( s:String ):Void {
videoMaru.playVideo( s );
play_btn.gotoAndStop(”paused”)
}
but I don’t know how to really address your MovieClips (pause/play)?
Thanks
Sorry Dan,
I think I’ve just sussed this? Adding this seemed to work:
function playVideo( s:String ):Void {
videoMaru.playVideo( s );
videoMaru.setIsPlaying(true);
}
@Richard, I think this has all been fixed in video.Maru 3.5 beta. Could you download it and see if it works with your setup?
Note that if you want to play an RTMP stream you’ll need to use:
videoMaru.playRTMP( s );
instead of
videoMaru.playVideo( s );
At least I had to.
Cheers
i try to download the source but the FLA wont open.
does it work in flash 8?
@dez, it should work. No one else has reported problems.