video.Maru
by polyGeek polyGeek logo



 

API docs

June 24th, 2007 . by polyGeek
polyGeek TV Learn how to use the video.Maru API to create a comboBox navigation.
polyGeek TV Use the video.Maru API to change the linkBTN text color when the btn is pressed.

Important: when accessing the video.Maru API you are targeting the SWC that you have placed in your FLA. You do not need to give the SWC an instance name because it does that for itself. That instance name is videoMaru.

The cornerstone to the video.Maru API is the videoMaruCreationComplete function. That is a function that you write and video.Maru will call that function for you when it has finished setting up the video interface.

The videoMaruCreationComplete function is where you’ll place code that is there to set or override certain properties of video.Maru. If for instance you wanted to change the size of the videoWindow on startup to reflect the dimensions reported by the FLV metaData then you’ll have to wait until the video.Maru code gets far enough that it knows what the videoWindow is. You can see a code sample of this below under getVideoMetaHeight.

It’s a good practice to place your videoMaruCreationComplete function on the same layer as the video.Maru SWC.

closeNetstream() ( beta )
Closing the Netstream object halts the download of the video stream and stops playback. When you click on a videoLink it will create a new Netstream and begin playback.

formatTime( s:String ):String
Takes a String that indicates a duration of time and returns a properly formated hour:minute:second display. Note: the reason it takes a String and not a Number is that the video metaData returns a String for the duration. Example: if you pass formatTime( 125 ) it will return 2:05.

getCurrentFLV():String
If you need to know what the current path/fileName.flv then use this. It would be handy if for instance you wanted to give someone the option to download the FLV to their system.

getIsPlaying():Boolean
Returns a true/false regarding the current state of playback. Usage: you might use this in an onEnterFrame if you want to track the current state of the playback so that when the video is not playing you could do something bandwidth intensive.

getLinkButtonArray():Array
Returns an array of all the linkBTNs corresponding to the videos listed in an XML file. Usage: you can loop through the array and add a number to the beginning of each linkBTN.link TextField. Or you could use it to change the appearance of a linkBTN after the user has played that video.

getVideoMetaHeight():Number
Returns the height of the video that is currently playing as reported by the metaData in the FLV. You cannot depend on this value being available in all cases. The Flash video encoder does add this metaData but not all encoders do. For instance the youTube videos that I have checked do not report the width/height in the metaData.

The code sample below will resize the videoWindow to fit the actual size of the FLV each time the video changes. If there is no width/height embedded in the metaData then it defaults to 320×240.

Note: there is a bit of a delay from the video starting to the resize. That’s caused by the delay in the Flash player reading the metaData. I don’t know of anything that can be done about that. Other than including the width/height in your XML file and getting the data from that. But that’s another project.

playVideo(s:String):Void
Send a path/filename.flv to this function and it will play that FLV, if it can be loaded.

setFadeTrayDuration(n:Number):Void
The fadeTray takes 1.5 seconds to fade in and out. If you would like to change that then pass in the number of seconds you would like to change it to. As an example if you wanted it to take 3 seconds to fade in and out then use this:

video.Maru.setFadeTrayDuration(3);

setFullScreenCallback(fn:Function):Void
description

setIsPlaying(b:Boolean):Void
You can bypass the play_btn/pause_btn with your own control by calling this function and passing the state of isPlaying. To pause the video call:

videoMaru.setIsPlaying(false);

This is especially useful if you want to have two separate buttons for the play and the pause. With the video.Maru interface that is not possible. You’ll have to create a button for each state - but don’t give them instance names of play_btn or pause_btn.

Here is some sample code for two buttons placed on the same layer as the video.Maru SWC

setLinkBtnPressed( fn:Function ):Void
Get notified when the user clicks on a linkBTN. Usage: you could use this to change the state of the button when pressed and then switch it back when released with setLinkBtnReleased().

setLinkBtnReleased( fn:Function ):Void
Get notified when the user clicks and releases on a linkBTN. Usage: you could use this to change the state of the button when pressed with setLinkBtnPressed() and then switch it back when released.

setMetaDataChangedCallback(fn:Function):Void
When the Flash player detects a change in the FLV metaData this function that you specify will be called. You can see an example of this under getVideoMetaHeight() above.

setMute(b:boolean):Void
Set the volume mute state: true/false.

setOnCuePoint( fn:Function ):Void
Set the callback function that is called when a cue point in your video is reached. You can read more about it here. Download the example.

setOnVideoComplete(fn:Function):Void
Set the callback function that is called when a video completes playing. See example.

setSmoothing(b:Boolean):Boolean
Turn smoothing on or off. Smoothing determines whether the video should be smoothed (interpolated) when it is scaled. For smoothing to work, the player must be in high-quality mode. The default value is false (no smoothing).

setVideoChangeCallback(fn:Function):Void
If set calls the function you specify when the FLV playing in the videoWindow is changed.

setVideoWindowHeight(n:Number):Void
Change the height of the videoWindow. See getVideoMetaHeight() above for an example.

setVideoWindowWidth(n:Number):Void
Change the width of the videoWindow. See getVideoMetaHeight() above for an example.

setVideoWindowX(n:Number):Void
Change the _x value of the videoWindow.

setVideoWindowY(n:Number):Void
Change the _y value of the videoWindow.

setXmlCallback(fn:Function):Void
Set a function to be called when the XML has been parsed into an object. The callback that you set needs to accept an argument of type Object. See below for an example.

toggleFullScreenVideo():Void
Toggles the fullScreen between fullScreen and in-browser views.

togglePlayPause():Void
Toggles the video playback between paused and playing. It will also change the state of your play_btn/pause_btn if available.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Technorati
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon

7 Responses to “API docs”

  1. comment number 1 by: Rick Deigsler

    Is there a way to programmatically adjust the volume?

  2. comment number 2 by: polyGeek

    @Rick, Currently the only API call for the volume is videoMaru.setMute( boolean ). I’m adding API calls to set the volume percentage in version 3.5. That should be out sometime in Q1 2008. But keep an eye out for the beta updates if you want to use it sooner.

  3. comment number 3 by: Josiah Williams

    Is there a way to programmatically adjust the playhead position? For example, if i want to set up markers that when clicked will advance the video to a certain position in time….

  4. comment number 4 by: Josiah Williams

    nevermind…I figured it out. If anyone else needs this feature, you may use this code:

    open _polyGeek.com-video.Maru 3.1 movieClip. Open up the actions for the frame on layer API

    go to the bottom and add this code:

    function setSeek(time:Number):Void{
    ns.seek( time );
    }

    then on your main timeline you could send your video to say 30 seconds by saying this:

    videoMaru.setSeek(30);

    This will also automatically update the playhead.

    Hope someone finds this useful.

  5. comment number 5 by: polyGeek

    @Josiah, I love it when people solve their own problems. Kudos to you!

    I’m not sure when I added this but the videoMaru 3.5 beta has that API call built in. It’s:

    videoMaru.setTimeIndex( number );

  6. comment number 6 by: Richard

    I’ve used the ’setVideoWindowHeight’ code you provide for detecting video-size (metadata) at runtime, which works perfectly.

    I’m trying to then get other GUI parts (captions) to position themselves based on the video size?

    I’m guessing I need to use ‘getVideoMetaHeight()’, but I’ve been unable to get this working?

    Basically I’m wanting the ‘captions’ box to sit below the video display regardless of that video size.

  7. comment number 7 by: polyGeek

    @Richard, are you doing this:
    var h:Number = videoMaru.getVideoMetaHeight();

Leave a Reply

Name

Mail (never published)

Website