4.4: Interfacing with your video player from JavaScript

The video player from 23 Video can be controlled from JavaScript -- that is, the video can be played and paused, and you can get information about the current playing video and the state of the video player.


Calling the video player from JavaScript

The JavaScript interface uses Flash's built-in ExternalInterface, and calling the exposed JavaScript simply requires a reference to the DOM object containing the video player. This can be done using a simple function responsible for handling different embed models in different browsers:

function getFlexApp(appName) { if (navigator.appName.indexOf ("Microsoft") !=-1) { return window[appName]; } else { return document[appName]; } }

We'll embed the video player with the ID/NAME videoplayer:

<object id="videoplayer" ...><embed name="videoplayer" ... /></object ...>

When you're embedding using straight HTML there's some trickery in making Flash interfacing work across browsers. The trick is to use both <object id="videoplayer" ...> and <embed name="videoplayer" ...>. Also, make sure the classid property is set while leaving out type and data on the <object> tag.

The standard embed code from 23 Video is built correctly -- but you'll need to add id and name.

This makes the video player calling very easy with a few lines of code:

var app = getFlexApp('videoplayer'); app.playVideo(); alert(app.getPlayState());

Whenever possible, it is suggested you embed video from 23 Video via JavaScript and SWFObject. The embed codes can be found within the administration interface and will also work using the exact same code as above:

<script src="http://yourvideodomain.com/resources/um/script/swfobject/swfobject.js"></script> <div id="videoplayer" class="embedded-video"> <div class="no-flash">You have an old version of Adobe's Flash Player ...</div> </div> <script> swfobject.embedSWF("http://yourvideodomain.com/v.swf", "videoplayer", "595", "340", "9.0.0", "/resources/um/script/swfobject/expressInstall.swf", {"photo_id": "12345"}, {allowscriptaccess:'always', allowfullscreen:'true'}, {id:'videoplayer', name:'videoplayer'}); </script>

Important note: The interface is only available after the DOM has been loaded in the browser. This means that you won't be able to use the code above during page load; it'll only work after the entire web page has been prepared.

See demos of both approaches:


Available methods

Method Description
.playVideo() Start playback.
.pauseVideo() Pause playback.
.getPlayState() Returns information about the current play state of the player. Possible values are buffering, playing, and paused.
.getPlayheadTime() Returns number of seconds played.
.setPlayheadTime(timeInSecs) Skips to a specific point in the video being played.
.getTotalTime() Returns total number of seconds in the currently playing video clip.
.getCurrentPhotoID() Return the ID of the currently playing video.
.getJSONSource() Returns the full URL of the JSON source used to populate the video player. This is useful if you need more information about the video being played.
.echo(echoValue) Returns the value of the argument. For example player.echo('23') will return 23. This is useful for testing.
.unloadVideoPlayer() Unloads the player. If possible, call this from the window.beforeunload event; it will stop playback and make optimize the user experience.

Adding new JavaScript methods to the player

The set of exposed functions or methods is fairly limited, but more can easily be added. Simply create your own custom player and add ExternalInterface callbacks to the init() method on VideoPlayer.mxml.

Comments

  1. Milena
    Great post! Thank you so much!
    » Milena
    October 27, 2011
  2. New Nike NFL Jersey
    When you want to show your support for your team, one of the best things that you can do is buy one New NFL Nike Jersey usnfljersey02.Showing individuals which player you like can be a good thing. Then you will notice that individuals will either respect you more or hate you more because of it. You will also find that the NFL Jersey Cheap can help you find new friends at the games because you will have something in common with the other people.Then, you will notice that you can guarantee that people will ask you questions about the player if they have never heard of the Authentic San Francisco 49ers Jersey before.When you let them know about the group that you support, it will be easy to see that they can agree with you. By knowing about these, it will be easy to enjoy the game and know that you are supporting the Wholesale NFL Jerseys. So your purchase of these jerseys could easily help keep the team.
    May 16, 2012
  3. q5251355
    Mulberry Handbags has become the first line of the brand Mulberry Bags, and their success is not measured in Mulberry UK action, Mulberry Sale has had a long investigation and analysis, continuous Mulberry Handbags Sale improvement and enrichment has Mulberry Bags UK a huge trend Mulberry Alexa in the world as the most representative and Mulberry Bayswater critical success factors that Mulberry Clutch Bags pattern bags may not interchangeable, other Mulberry Cross Body Bags, and there's no doubt about Mulberry Hobo. Monogram bag has a recognizable Mulberry Shoulder Bags pattern combinations initials Mulberry Messenger Bags and floral patterns, everyone knows Light-Grey Mulberry Bayswater Anthracite Ostrich Holdalls Bag change that difference, regardless of the Mulberry Daria Clutch Purse Black and no matter what happens, Mulberry Slim Brynmore in Navy Smooth Touch is important to be ignored, and although there are a variety of styles, patterns Mulberry Handbags Charm Roomy Dark Orange is still the center of the design Mulberry Daria Soft Leather Cross Body Bag Purple that will be mainly divided into several obvious reasons.
    Own more than 100 years history, Mulberry Bag is most people’s favorite for it’s real leather material and exterior originality. Fashion mulberry design with more pockets, buckles and more beautiful with practical with rivets, make the mulberry popularity worldwide. Specialized in the leather, forged by masterly craft, Mulberry Factory Shop sale Mulberry Handbags, Mulberry Alexa,Bags, Mulberry Bayswater Bags, Mulberry Clutch Bags, Mulberry Purse, Mulberry Hobo Bags,etc. Top quality Mulberry sale in the Mulberry UK Shop, combined with the practical, creating original and leather tactility, Mulberry Handbags UK try to be unique creative design. Full collection of Mulberry Bags with different leather materials and sizes in the Mulberry Bag online shop, mulberry calf leather bags, mulberry ostrich leather bags, mulberry buffalo leather bags,etc. Mulberry oversized, Mulberry big size, Mulberry small size,etc. Welcome to our store, mulberry outlet all kinds of high quality mulberry bags to you, free shipping!
    To find a suitable handbags is very important to people’s image, and where to find the most suitable bag to enhance self image? Mulberry Factory shop have full collection of Mulberry Bags let you choose. Luxury British top brand Mulberry own more than 100 years history and has long been recognized for its highly crafted fine leather goods. Use different materials design various Mulberry Bags to meet different people’s need, mulberry calf leather bags, mulberry patent leather bags, Mulberry Buffalo leather bags, Mulberry ostrich leather bags,etc. From oversized mulberry bags to small size mulberry bags, Mulberry Bags are very popular around the world. All kinds of Mulberry leather Bags with stylish style and fashion season, Mulberry Alexa Bags , Mulberry Bayswater Bags , Mulberry Mitzy Hobo , Mulberry Clutch Bags , Mulberry Handbags , Mulberry Mens Bags ,etc. Mulberry bag always keep pace with the trends of the times, so take mulberry leather bag will let you never out of date.
     
    » q5251355
    May 21, 2012
  4. tn pas che
  5. دردشة بنات مصريه

Add a comment...

Name
E-mail
Web
 
Connect with Faceboook
Content