header_graphic
header_gradient
 
  • Posted by ESA
  • Comments Off

With the ESA HD Media Player you can use JavaScript in your html document to load new media items (e.g. using text or thumbnail links), request information from the player (e.g. current media path), and control the media playback (e.g. play/pause). To enable the JavaScript interactivity, the embed script in the web page must be set up as shown below, the JavaScript functions and onClick events in the web page must be set up as shown below, the “mediaSource” parameter in the MediaPlayer’s Component Inspector must be undefined prior to publishing the SWF (undefined by default), and the action script in this post must be in the actions panel (included in all v.2 skins). Please keep in mind, using this tutorial and our online documentation (includes API), you can expand the JavaScript capabilities of this player to meet the needs of almost any project.

Click Here To See A Working JavaScript Example

Embed Script:
Below is a typical set of object and embed tags used to embed one of our players into a webpage. To enable the JavaScript functions discussed below, you must use the “id” and “name” attributes (red text; set to “ESAHDMP” to work with JS below), and you must set the “allowscriptaccess” to “always”. If you are not familiar with our recommended embed script, please see the “Simple Embed” and “FlashVars Media Loading” tutorials for more details.

<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ codebase=
“http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0″
width=”640″ height=”390″ id=”ESAHDMP” >
<param name=”movie” value=”default.swf” />
<param name=”allowfullscreen” value=”true”/>
<param name=”allowscriptaccess” value=”always”/>

<param name=”FlashVars” value=”media=media.xml” />
<param name=”wmode” value=”transparent” />
<embed src=”default.swf” width=”640″ height=”390″ FlashVars=”media=media.xml”
allowfullscreen=”true”allowscriptaccess=”always” type=”application/x-shockwave-flash”
wmode=”transparent” pluginspage=”http://www.macromedia.com/go/getflashplayer”
name=”ESAHDMP”/>
</object>

JavaScript:
The following JavaScript (JS) functions must be defined in the header of your html document. Notice all of the functions refer to “ESAHDMP” as the “MovieName”, which is the player id/name as defined in the embed script above (red text). The only required JS function is ”getFlashMovie”. The other JS functions are used to call specific Action Script (AS) methods in the player to perform specific tasks. For example, JS function “SendMediaToFlashMovie” calls AS method “sendMediaToFlash”, which loads a specified media file; JS function “GetMediaFromFlashMovie” calls AS method “queryMediaFromFlash”, which returns the path to the current media file; JS function “SendXMLToFlashMovie” calls AS method “sendXMLToFlash”, which loads a specified xml file; JS function “SendNameToFlashMovie” calls AS method “sendNameToFlash”, which forces the player to jump to the XML item with matching “name” attribute; JS function “SendIDToFlashMovie” calls AS method “sendIDToFlash”, which forces the player to jump to the XML item with matching “id” attribute; JS function “PlayMediaInFlashMovie” calls AS method “playMediaInFlash”, which plays the current media file if it is paused; and JS function “PauseMediaInFlashMovie” calls AS method “pauseMediaInFlash”, which pauses the current media file if it is playing. 

<script > 
function getFlashMovie(movieName) {  
 var isIE = navigator.appName.indexOf(”Microsoft”) != -1;  
 return (isIE) ? window[movieName] : document[movieName]; 

function SendMediaToFlashMovie(param) {    
 getFlashMovie(”ESAHDMP“).sendMediaToFlash(param);    
}
function GetMediaFromFlashMovie() {    
 document.loader.Data.value=getFlashMovie(”ESAHDMP“).queryMediaFromFlash();
}
function SendXMLToFlashMovie(param) {    
 getFlashMovie(”ESAHDMP“).sendXMLToFlash(param);    
}
function SendNameToFlashMovie(param) {    
 getFlashMovie(”ESAHDMP“).sendNameToFlash(param);    
}
function SendIDToFlashMovie(param) {    
 getFlashMovie(”ESAHDMP“).sendIDToFlash(param);    
}
function PlayMediaInFlashMovie() {    
 getFlashMovie(”ESAHDMP“).playMediaInFlash();
}
function PauseMediaInFlashMovie() {    
 getFlashMovie(”ESAHDMP“).pauseMediaInFlash();
}
</script>

“onClick” event handlers in the body of your html document are used to call the JavaScript header functions when an item on the page is clicked. The “onClick” event handler can be used with text links, thumbnails, and forms (with textfields and buttons) as shown below.

Text Link Syntax Examples:
<span onClick=”SendMediaToFlashMovie(’MEDIA-PATH’);”>HTML-TEXT</span>
<span onClick=”SendXMLToFlashMovie(’XML-PATH’);”>HTML-TEXT</span>
<span onClick=”SendIDToFlashMovie(’MEDIA-XML-ID’);”>HTML-TEXT</span>
<span onClick=”SendNameToFlashMovie(’MEDIA-XML-NAME’);”>HTML-TEXT</span>

Thumbnail Syntax Examples:
<img src=”IMAGE-PATH” onClick=”SendMediaToFlashMovie(’MEDIA-PATH’);” />
<img src=”IMAGE-PATH” onClick=”SendIDToFlashMovie(’MEDIA-XML-ID’);” />
<img src=”IMAGE-PATH” onClick=”SendNameToFlashMovie(’MEDIA-XML-NAME’);” />

Form Syntax to Load and Query Media:
<FORM name=”loader” method=”post”>
  <INPUT value=”Sample Text” name=”Data” size=”32″ />
  <INPUT onClick=”SendMediaToFlashMovie(document.loader.Data.value);” type=”button” value=”Load” name=”SendData” />
  <INPUT onClick=”GetMediaFromFlashMovie();” type=”button” value=”Query” name=”ReceiveData” />
</FORM>

Form Syntax for Play/Pause Buttons:
<FORM name=”controller” method=”post”>
  <INPUT onClick=”PlayMediaInFlashMovie();” type=”button” value=”Play” name=”PlayMedia” />
  <INPUT onClick=”PauseMediaInFlashMovie();” type=”button” value=”Pause” name=”PauseMedia” />
</FORM>

Action Script 3.0:
The following AS must be defined in the player FLA to handle the JS on-click event functions discussed above (updated for v.2).

//—Interact With MediaPlayer Using Java Script—
import flash.external.ExternalInterface;
import flash.events.Event;

//—load single audio/video file
ExternalInterface.addCallback(”sendMediaToFlash”, loadMediaFromJavaScript);
function loadMediaFromJavaScript(str:String):void { 
 if(myMediaPlayer.mediaSource != str && myMediaPlayer.roll == false){
  myMediaPlayer.loadMedia(str); //enable to load single files or XML with “.xml” extension
 }  
}

//—get current media
ExternalInterface.addCallback(”queryMediaFromFlash”, getMediaForJavaScript);
function getMediaForJavaScript():String { 
 return myMediaPlayer.mediaSource;
}

//—load xml playlist
ExternalInterface.addCallback(”sendXMLToFlash”, loadXMLFromJavaScript); function loadXMLFromJavaScript(str:String):void { 
 if(myMediaPlayer.mediaSource != str && myMediaPlayer.roll == false){
  myMediaPlayer.loadXML(str);
 }  
}

//—jump to XML item with corresonding “name” attribute
ExternalInterface.addCallback(”sendNameToFlash”, loadNameFromJavaScript);
function loadNameFromJavaScript(str:String):void { 
 if(myMediaPlayer.currentName != str && myMediaPlayer.roll == false){
  myMediaPlayer.jumpToName(str);
 }  
}

//—jump to XML item with corresonding “id” attribute
ExternalInterface.addCallback(”sendIDToFlash”, loadIDFromJavaScript);
function loadIDFromJavaScript(num:Number):void { 
 if(myMediaPlayer.currentID != num && myMediaPlayer.roll == false){
  myMediaPlayer.jumpToID(num);
 }  
}

//—play media
ExternalInterface.addCallback(”playMediaInFlash”, playMediaForJavaScript);
function playMediaForJavaScript():void { 
 return myMediaPlayer.play();
}

//—pause media
ExternalInterface.addCallback(”pauseMediaInFlash”, pauseMediaForJavaScript);
function pauseMediaForJavaScript():void { 
 return myMediaPlayer.pause();
}

Working with a Flash Media Server?
If you are loading media files that are hosted on a Flash Media Server you should refer to our tutorial, “Working With A Flash Media Server” for instructions.

  • Posted by ESA
  • Comments Off

The HD Media Player supports the use of FlashVars in the html “Flash Object and Embed Tags” for dynamic media loading. To enable the use of FlashVars, the embed script must be set up as shown below, the “mediaSource” parameter in the MediaPlayer’s Component Inspector must be blank prior to publishing the SWF (should be blank by default), and the action script in this post must be in the actions panel (included in all skins).

Embed Script:
Below is a typical set of object and embed tags used to embed one of our players into a webpage (notice the FlashVars in red). If you are not familiar with our recommended embed script, please see the “Simple Embed” tutorial for more details.

<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″
codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0″
width=”640″ height=”390″ id=”ESAHDMP” >
<param name=”movie” value=”default.swf” />
<param name=”allowfullscreen” value=”true”/>
<param name=”allowscriptaccess” value=”always”/>
<param name=”FlashVars” value=”media=media.xml” />
<param name=”wmode” value=”transparent” />
<embed src=”default.swf” width=”640″ height=”390″ FlashVars=”media=media.xmlallowfullscreen=”true”
allowscriptaccess=”always” type=”application/x-shockwave-flash” wmode=”transparent”
pluginspage=”http://www.macromedia.com/go/getflashplayer” name=”ESAHDMP” />
</object>

With all of our default players (starting v.1.5.3), you can use following FlashVars to configure the player on pageload:

  • autoplay – Options: “Yes-always”, “Yes-on first video”, “No-always”, “No-on first video”.
  • image - Absolute or relative path to an image file to be used as a preloader, pause image, or in support of an audio file. If you use a relative path it must be relative to the location of the page where the SWF is displayed, not the location of the SWF on your server.
  • link – URL where user will be directed if they click the screen.
  • instance – Options: “application” or ”stream”. Determines if the first instance in a rtmp path should be attributed to the application or stream name. For example: if your rtmp path is rtmp://www.server.com/application/instance/stream, and /instance/ is part of the stream name choose “stream”; or if /instance/ is part of the application name choose “application”.
  • media – Absolute or relative path to a single audio/video file or a XML playlist file that has the “.xml” extension. In the above example, the player would load “media.xml”. If you use a relative path it must be relative to the location of the page where the SWF is displayed, not the location of the SWF on your server. Progressive (http) and streaming (rtmp or rtmpe) protocols are supported for audio and video files, meaning you can host your media files on any standard web server, Flash Media Server 3/4 (FMS or FMIS), Wowza, Red5, or YouTube.
  • xml - Absolute or relative path to a XML playlist file that does not have the “.xml” extension (e.g. xml generated with ASP or PHP). If you use a relative path it must be relative to the location of the page where the SWF is displayed, not the location of the SWF on your server.
  • wizard – (v.2 or later) wizard settings array; this variable should only be used with the Skin Wizard.

You must choose either the “media” or “xml” FlashVars to load your media item(s) – you can not use both at the same time. Typically, when you load a XML file the other FlashVars are unnecessary, because those variables can be defined in the XML. When loading single media items, you can define multiple FlashVars using the “&” symbol as a separator, and the “media” FlashVars should be defined last, as shown below:

“autoplay=No-always&image=image.jpg&link=http://www.domain.com&media=video.flv”

Action Script 3.0:
The following action script detects the FlashVars (red text) in the embed code upon pageload and passes those variables into the MediaPlayer component at run-time. This script is included in our default player FLA (v.2 or later; differs slightly in previous version numbers and other skins), and can be accessed in the actions panel (scene 1, frame 1).

//—Load Media Using FlashVars—
if(myMediaPlayer.mediaSource == “”){
try {
var media:String;
var id:*;
var xml:Boolean;
var keyStr:String;
var valueStr:*; //String
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
valueStr = String(paramObj[keyStr]);
if(keyStr == “autoplay“) myMediaPlayer.mediaAutoPlay = valueStr;
if(keyStr == “image“) myMediaPlayer.imageSource = valueStr;
if(keyStr == “link“) myMediaPlayer.mediaLink = valueStr; //must set link target in fla or xml
if(keyStr == “instance“) myMediaPlayer.mediaSourceInstance = valueStr;
if(keyStr == “media” && media == “”) media = valueStr;
if(keyStr == “id” && id == 0) id = valueStr;
if(keyStr == “xml” && media == “”){
xml = true;
media = valueStr;
}
if(keyStr == “wizard“){
config(valueStr.split(”,”));
}
}
} catch (error:Error) {
trace(”Undefined Media”);
}
if(id != 0){
myMediaPlayer.loadXMLAtID(media,id);
} else if(id == 0 && xml){
myMediaPlayer.loadXML(media);
} else {
myMediaPlayer.loadMedia(media);
}
}

Working with a Flash Media Server?
If you are loading media files that are hosted on a Flash Media Server you should refer to our tutorial, “Working With A Flash Media Server” for instructions.

footer_graphic

Home - FAQs - Support - Contact - Licensing, Refunds & Shipping - Downloads & Upgrades - Google Checkout
Purchase HD Media Player - Documentation - Skin Wizard - Sample Skins - Tutorials
Flash CS4 AS 3.0 HD Media Player Customization, Implementation, and Web Video Encoding Services
Copyright © 2003-2011 Earth Science Agency, LLC - All Rights Reserved