Changeset 1342


Ignore:
Timestamp:
09/29/10 15:01:49 (3 years ago)
Author:
pablo
Message:

Updating JavaScript documentation to reflect new API; including API reference in embedding guide

Location:
trunk/fl5/doc
Files:
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/fl5/doc/publishers/conf.py

    r1339 r1342  
    7878latex_documents = [ 
    7979  ('index','JWPlayerFlash.tex','JW Player for Flash','www.longtailvideo.com','manual',True), 
    80   ('embedguide','JWPlayerEmbedder.tex','JW Player for Flash and HTML5','Embedding Guide','manual',True) 
     80  ('embedguide','JWPlayerEmbedGuide.tex','JW Player for Flash and HTML5','Embedding Guide','manual',True) 
    8181] 
    8282 
  • trunk/fl5/doc/publishers/embedding.rst

    r1339 r1342  
    2121.. note:: 
    2222 
    23 We recommend putting everything in a folder called "jwplayer" at the root of your site.  This enables the :ref:`quickembed` method of setting up the player. 
     23        We recommend putting everything in a folder called "jwplayer" at the root of your site.  This enables the :ref:`quickembed` method of setting up the player. 
    2424 
    2525 
     
    106106.. note::  
    107107 
    108    As you can see, the Flash version reference is not in the embed tag: this is one of the drawbacks of this method: it's not possible to sniff for Flash and selectively hide it, e.g. if the flash version is not sufficient or if the device (iPad ...) doesn't support Flash. 
     108   The Flash version reference is not in the embed tag: this is one of the drawbacks of this method: it's not possible to detect Flash and selectively hide it, e.g. if the flash version is not sufficient or if the device (iPad ...) doesn't support Flash. 
    109109    
    110110JW Embedder 
     
    246246.. note:: 
    247247 
    248 If you're configuring the Embedder to run primarily in HTML5 mode using the :ref:`embed_players` block, you'll need to take the additional step of unzipping the skin ZIP and uploading its contents to your web server in the same location as the ZIP file itself.  Your skin's folder structure would look something like this: 
     248        If you're configuring the Embedder to run primarily in HTML5 mode using the :ref:`embed_players` block, you'll need to take the additional step of unzipping the skin ZIP and uploading its contents to your web server in the same location as the ZIP file itself.  Your skin's folder structure would look something like this: 
    249249 
    250250.. code-block:: text 
  • trunk/fl5/doc/publishers/embedguide.rst

    r1339 r1342  
    55    
    66   embedding 
     7   javascriptapi 
  • trunk/fl5/doc/publishers/javascriptapi.rst

    r1214 r1342  
    11.. _javascriptapi: 
    22 
    3 JavaScript API 
    4 ============== 
    5  
    6 The JW Player for Flash supports a flexible JavaScript API. It is possible to read the config/playlist variables of the player, send events to the player (e.g. to pause or load a new video) and listen (and respond) to player events. A small initialization routine is needed to connect your apps to the player. 
    7  
    8  
    9 Initialization 
    10 -------------- 
    11   
    12 Please note that the player will **NOT** be available the instant your HTML page is loaded and the first JavaScript is executed. The SWF file (90k) has to be loaded and instantiated first! You can catch this issue by defining a simple global JavaScript function. By default, it is called *playerReady()* and every player that's successfully instantiated will call it.  
     3Player API 
     4========== 
     5 
     6The 5.3 player introduces a new, shorthand javascript API for interacting with your website. This API abstracts any differences between Flash and HTML5; any code you write will work with both technologies. 
     7 
     8For versions 5.2 and below, the player used the 4.x JavaScript API.  A reference for that API can be found on the `player support site <http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v4/12209/javascript-api-reference>`_. 
     9 
     10 
     11Getting started 
     12--------------- 
     13 
     14To get a sense of the possibilities, here's a quick example that showcases how to control the player from the page: 
    1315 
    1416.. code-block:: html 
    15  
    16    var player; 
    17    function playerReady(object) { 
    18      alert('the player is ready'); 
    19      player = document.getElementById(object.id); 
    20    }; 
    21  
    22  
    23 The *object* the player sends to the function contains the following properties: 
    24  
    25 .. describe:: id 
    26  
    27    ID of the player (the *<embed>* code) in the HTML DOM. Use it to get a reference to the player with *getElementById()*. 
    28  
    29 .. describe:: version 
    30  
    31    Exact version of the player in MAJOR.MINOR.REVISION format *e.g. 5.2.1065*. 
    32  
    33 .. describe:: client 
    34  
    35   Plugin version and platform the player uses, e.g. *FLASH WIN 10.0.47.0*. 
    36  
    37 .. note:: On Windows and Mac OS X, the player automatically reads its *ID* from the *id* and *name* attributes of the player's `HTML embed code <embedding>`. On Linux however, this functionality **does not work**. If you target Linux users with your scripting, you can circumvent this issue by including an  :ref:`id option <options-behavior>` in your list of flashvars in the embed code. 
    38  
    39  
    40 Custom playerready 
    41 ^^^^^^^^^^^^^^^^^^ 
    42  
    43 It is possible to ask the player to call a different javascript function after it completes its initialization. This can be done with an :ref:`option <options>` called **playerready**. Here is an example SWFObject :ref:` embed code <embedding>` using the function *registerPlayer()*: 
     17     
     18    <div id="container">Loading the player ...</div> 
     19     
     20    <script type="text/javascript"> 
     21        jwplayer("container").setup({ 
     22            flashplayer: "/jwplayer/jwplayer.swf", 
     23            file: "/uploads/video.mp4", 
     24            height: 270, 
     25            width: 480 
     26        }); 
     27    </script> 
     28     
     29    <ul> 
     30        <li onclick="jwplayer().play()">Start the player</li> 
     31        <li onclick="alert(jwplayer().getPosition())">Get current position</li> 
     32    </ul> 
     33 
     34Of course it's also possible to have the player manipulate the page. Here's a second example, using the  :ref:`event block <embed_events>` of the JW Player embedder: 
    4435 
    4536.. code-block:: html 
    46  
    47    <p id="container1">You don't have Flash ...</p> 
    48  
    49    <script type="text/javascript"> 
    50      var flashvars = { file:'/data/bbb.mp4',playerready:'registerPlayer' }; 
    51      var params = { allowfullscreen:'true', allowscriptaccess:'always' }; 
    52      var attributes = { id:'player1', name:'player1' }; 
    53      swfobject.embedSWF('player.swf','container1','480','270','9.0.115','false', 
    54        flashvars, params, attributes); 
    55  
    56      var player; 
    57      function registerPlayer(obj) {  
    58        alert('The player with ID '+obj.id + 'is ready!'); 
    59        player = document.getElementById(obj.id); 
    60      }; 
    61    </script> 
    62  
    63 No playerready 
    64 ^^^^^^^^^^^^^^ 
    65  
    66 If you are not interested in calling the player immediately after the page loads, you won't need the *playerReady()* function. You can then simply use the ID of the embed/object tag that embeds the player to get a reference. So for example with this embed tag: 
     37     
     38    <div id="container">Loading the player ...</div> 
     39     
     40    <script type="text/javascript"> 
     41        jwplayer("container").setup({ 
     42            flashplayer: "/jwplayer/jwplayer.swf", 
     43            file: "/uploads/video.mp4", 
     44            height: 270, 
     45            width: 480, 
     46            events: { 
     47                onComplete: function() {  
     48                    document.getElementById("status").innerHTML("That's all folks!");  
     49                } 
     50            } 
     51        }); 
     52    </script> 
     53     
     54    <p id="status"></p> 
     55 
     56The following sections give a detailed description of the JW Player API, describing how to: 
     57 
     58* Select a player. 
     59* Get variables from a player. 
     60* Call functions on a player. 
     61* Listen to events from a player. 
     62 
     63 
     64Selecting 
     65--------- 
     66 
     67The first thing you need to do when attempting to interact with a JW Player, is to get a reference to it. The easiest way, probably sufficient for 95% of all use cases is this: 
     68 
     69.. code-block:: javascript 
     70 
     71    // Start the player on this page 
     72    jwplayer().play(); 
     73 
     74 
     75Only when you have multiple players on a page, you need to be more specific on which player you want to interact with. In that case, there are three ways to select a player: 
     76 
     77* With the *id* of the element you :ref:`instantiated <embed>` the player over: 
     78     
     79    .. code-block:: javascript 
     80     
     81        jwplayer("container").play(); 
     82 
     83* With the actual DOM element itself: 
     84     
     85    .. code-block:: javascript 
     86     
     87        var element = document.getElementById("container"); 
     88        jwplayer(element).play(); 
     89 
     90* With the index in the list of players on the page (in order of loading): 
     91    
     92    .. code-block:: javascript 
     93       
     94        jwplayer(2).play(); 
     95     
     96    .. note:: 
     97     
     98        The selector *jwplayer(0)* is actually the same as *jwplayer()*. 
     99 
     100 
     101 
     102Variables 
     103--------- 
     104 
     105Here is a list of all the variables that can be retrieved from the player: 
     106 
     107.. describe:: getBuffer() 
     108 
     109    Returns the current PlaylistItem's filled buffer, as a **percentage** (0 to 100) of the total video's length. 
     110     
     111.. describe:: getFullscreen() 
     112 
     113    Returns the player's current **fullscreen** state, as a boolean (*true* when fullscreen). 
     114 
     115.. describe:: getMetadata() 
     116 
     117    Returns the current PlaylistItem's **metadata**, as a javascript object. This object contains arbitrary key:value parameters, depending upon the type of player, media file and streaming provider that is used. Common metadata keys are *width*, *duration* or *videoframerate*. 
     118 
     119.. describe:: getMute() 
     120 
     121    Returns the player's current audio muting state, as a boolean (*true* when there's no sound). 
     122 
     123.. describe:: getPlaylist() 
     124 
     125    Returns the player's entire **playlist**, as an array of PlaylistItem objects. Here's an example playlist, with three items: 
     126     
     127    .. code-block:: javascript 
     128     
     129        [ 
     130            { duration: 32, file: "/uploads/video.mp4", image: "/uploads/video.jpg" }, 
     131            { title: "cool video", file: "/uploads/bbb.mp4" }, 
     132            { duration: 542, file: "/uploads/ed.mp4", start: 129 } 
     133        ] 
     134 
     135.. describe:: getPlaylistItem(*index*): 
     136 
     137    Returns the playlist **item** at the specified *index*. If the *index* is not specified, the currently playing playlistItem is returned. The **item**  that is returned is an object with key:value properties (e.g. *file*, *duration* and *title*). Example: 
     138     
     139    .. code-block:: javascript 
     140     
     141        { duration: 32, file: "/uploads/video.mp4", image: "/uploads/video.jpg" } 
     142 
     143.. describe:: getWidth() 
     144 
     145    Returns the player's current **width**, in pixels. 
     146 
     147.. describe:: getHeight() 
     148 
     149    Returns the player's current **height**, in pixels. 
     150 
     151.. describe:: getState() 
     152 
     153    Returns the player's current playback state. It can have the following values: 
     154     
     155    * **BUFFERING**: user pressed *play*, but sufficient data has to be loaded first (no movement). 
     156    * **PLAYING**: the video is playing (movement).  
     157    * **PAUSED**: user paused the video (no movement). 
     158    * **IDLE**: either the user stopped the video or the video has ended (no movement). 
     159 
     160.. describe:: getPosition() 
     161 
     162    Returns the current playback **position** in seconds, as a number. 
     163 
     164.. describe:: getDuration() 
     165 
     166    Returns the currently playing PlaylistItem's duration in seconds, as a number. 
     167 
     168.. describe:: getVolume() 
     169 
     170    Returns the current playback volume percentage, as a number (0 to 100). 
     171 
     172 
     173 
     174Functions 
     175--------- 
     176 
     177Here is a list of all functions that can be called on the player: 
     178 
     179.. describe:: setFullscreen(state) 
     180 
     181    Change the player's fullscreen mode. Parameters: 
     182     
     183    * **state**:Boolean (*undefined*): If state is undefined, perform a fullscreen toggle. Otherwise, set the player's fullscreen mode to fullscreen if true, and return to normal screen mode if false. 
     184 
     185.. describe:: setMute(state) 
     186 
     187    Change the player's mute state (no sound). Parameters: 
     188 
     189    * **state**:Boolean (undefined): If *state* is undefined, perform a muting toggle. Otherwise, mute the player if true, and unmute if false. 
     190 
     191.. describe:: load(playlist) 
     192 
     193    Loads a new playlist into the player. The **playlist** parameter is required and can take a number of forms: 
     194     
     195    * *Array*: If an array of PlaylistItem objects is passed, load an entire playlist into the player. Example: 
     196     
     197        .. code-block:: javascript 
     198         
     199            [ 
     200                { duration: 32, file: "/uploads/video.mp4", image: "/uploads/video.jpg" }, 
     201                { title: "cool video", file: "/uploads/bbb.mp4" }, 
     202                { duration: 542, file: "/uploads/ed.mp4", start: 129 } 
     203            ] 
     204 
     205    * *Object*: If a PlaylistItem is passed, load it as a single item into the player. Example: 
     206     
     207        .. code-block:: javascript 
     208         
     209            { duration: 32, file: "/uploads/video.mp4", image: "/uploads/video.jpg" }, 
     210         
     211    * *String*: Can be an XML playlist, or the link to a single media item (e.g. an MP4 video). 
     212 
     213.. describe:: playlistItem(index) 
     214 
     215    Jumps to the playlist item at the specified index. Parameters: 
     216     
     217    * **index**:Number: zero-based index into the playlist array (i.e. playlistItem(0) jumps to the first item in the playlist). 
     218 
     219.. describe:: playlistNext() 
     220 
     221    Jumps to the next playlist item. If the current playlist item is the last one, the player jumps to the first. 
     222 
     223.. describe:: playlistPrev() 
     224 
     225    Jumps to the previous playlist item. If the current playlist item is the first one, the player jumps to the last. 
     226 
     227.. describe:: resize(width, height) 
     228 
     229    Resizes the player to the specified dimensions. Parameters: 
     230     
     231    * **width**:Number: the new overall width of the player. 
     232    * **height**:Number: the new overall height of the player. 
     233     
     234    .. note:: 
     235     
     236        If a controlbar or playlist is displayed next to the video, the actual video is of course smaller than the overall player. 
     237 
     238.. describe:: play(state) 
     239 
     240    Toggles playback of the player. Parameters: 
     241     
     242    * **state**:Boolean (undefined): if set *true* the player will start playing. If set *false* the player will pause. If not set, the player will toggle playback. 
     243 
     244 
     245.. describe:: pause(state) 
     246 
     247    Toggles playback of the player. Parameters: 
     248     
     249    * **state**:Boolean (undefined): if set *true* the player will pause playback. If set *false* the player will play. If not set, the player will toggle playback. 
     250     
     251.. describe:: stop() 
     252 
     253    Stops the player and unloads the currently playing media file from memory. 
     254 
     255.. describe:: seek(position) 
     256 
     257    Jump to the specified position within the currently playing item. Parameters: 
     258 
     259    * **position**:Number: Requested position in seconds. 
     260 
     261.. describe:: setVolume(volume) 
     262 
     263    Sets the player's audio volume. Parameters: 
     264     
     265    * **volume**:Number: The new volume percentage; *0* and *100*. 
     266 
     267 
     268 
     269Events 
     270------ 
     271 
     272Here is a list of all events the player supports. In javascript, you can listen to events by assigning a function to it. Your function should take one argument (the event that is fired). Here is a code example, with some javascript that listens to changes in the volume: 
     273 
     274.. code-block:: javascript 
     275     
     276    jwplayer("container").onVolume( 
     277        function(event) {  
     278            alert("the new volume is: "+event.volume); 
     279        } 
     280    ); 
     281 
     282Note that our :ref:`official embed method <embed>` contains a shortcut for assigning event listeners, directly in the embed code: 
    67283 
    68284.. code-block:: html 
    69  
    70    <embed id="myplayer" name="myplayer" src="/upload/player.swf" width="400" height="200" /> 
    71  
    72 You can get a pointer to the player with this line of code: 
    73  
    74 .. code-block:: html 
    75  
    76    var player = document.getElementById('myplayer'); 
    77  
    78 .. note::  
    79  
    80    Note you must add both the **id** and **name** attributes in the *<embedding>* in order to get back an ID in all browsers. 
    81  
    82  
    83 Reading variables 
    84 ----------------- 
    85  
    86 There's two variable calls you can make through the API: *getConfig()* and *getPlaylist()*. 
    87  
    88 getConfig() 
    89 ^^^^^^^^^^^ 
    90  
    91 getConfig() returns an object with state variables of the player. For example, here we request the current audio volume, the current player width and the current playback state: 
    92  
    93 .. code-block:: html 
    94  
    95    var volume = player.getConfig().volume; 
    96    var width = player.getConfig().width; 
    97    var state = player.getConfig().state; 
    98  
    99 Here's the full list of state variables: 
    100  
    101 .. describe:: bandwidth 
    102  
    103    Current bandwidth of the player to the server, in kbps (e.g. *1431*). This is only available for the :ref:video  <mediaformats>`, :ref:`http <httpstreaming>` and :ref:`rtmp <rtmpstreaming>` providers. 
    104  
    105 .. describe:: fullscreen 
    106  
    107    Current fullscreen state of the player, as boolean (e.g. *false*). 
    108  
    109 .. describe:: height 
    110  
    111    Current height of the player, in pixels (e.g. *270*). 
    112  
    113 .. describe:: item 
    114  
    115    Currently active (playing, paused) playlist item, as zero-index (e.g. *0*). Note that *0* means the first playlistitem is playing and *1* means the second one is playing. 
    116  
    117 .. describe:: level 
    118  
    119    Currently active bitrate level, in case multipe bitrates are supplied to the player. This is only useful for  :ref:`httpstreaming` and :ref:`rtmpstreaming`. Note that *0* always refers to the highest quality bitrate. 
    120  
    121 .. describe:: state 
    122  
    123    Current playback state of the player, as an uppercase string. It can be one of the following: 
    124  
    125    * *IDLE*: The current playlist item is not loading and not playing. 
    126    * *BUFFERING*: the current playlistitem is loading. When sufficient data has loaded, it will automatically start playing. 
    127    * *PLAYING*: the current playlist item is playing. 
    128    * *PAUSED*: playback of the current playlistitem is not paused by the player. 
    129  
    130 .. describe:: mute 
    131  
    132    Current audio mute state of the player, as boolean (e.g. *false*).  
    133  
    134 .. describe:: volume 
    135  
    136    Current audio volume of the player, as a number from 0 to 100 (e.g. *90*).  
    137  
    138 .. describe:: width 
    139  
    140    Current width of the player, in pixels (e.g. *480*). 
    141  
    142 .. Note::  
    143  
    144    In fact, all the :ref:`options` will be available in the response to *getConfig()*. In certain edge cases, this might be useful, e.g. when you want to know if the player did **autostart** or not. 
    145  
    146  
    147 getPlaylist() 
    148 ^^^^^^^^^^^^^ 
    149  
    150 getPlaylist() returns the current playlist of the player as an array. Each entry of this array is in turn again a hashmap with all the :ref:`playlist properties <playlistformats>` the player recognizes. Here's a few examples: 
    151  
    152 .. code-block:: html 
    153  
    154    var playlist = player.getPlaylist(); 
    155    alert("There are " + playlist.length + " videos in the playlist"); 
    156    alert("The title of the first entry is " + playlist[0].title); 
    157    alert("The poster image of the second entry is " + playlist[1].image); 
    158    alert("The media file of the third entry is " + playlist[2].file); 
    159    alert("The media provider of the fourth entry is " + playlist[3].provider); 
    160  
    161 Playlist items can contain properties supported by the provider. Examples of such properties are: 
    162  
    163 * **http.startparam**, when using the :ref:`HTTP provider <httpstreaming>`. 
    164 * **rtmp.loadbalance**, when using the :ref:`RTMP provider <rtmpstreaming>`. 
    165  
    166 Playlist items can  also contain properties supported by certain plugins. Examples of such properties are: 
    167  
    168 * **hd.file**, which is used by the HD plugin. 
    169 * **captions.file**, which is used by the Captions plugin. 
    170  
    171 More information, and the full list of 12 default playlist properties, can be found in :ref:`playlistformats`. 
    172  
    173 Sending events 
    174 -------------- 
    175  
    176 The player can be controlled from JavaScript by sending events (e.g. to pause it or change the volume). Sending events to the player is done through the *sendEvent()* call. Some of the event need a parameter and some don't. Here's a few examples: 
    177  
    178 .. code-block:: html 
    179  
    180    // this will toggle playback. 
    181    player.sendEvent("play"); 
    182    // this sets the volume to 90% 
    183    player.sendEvent("volume","true"); 
    184    // This loads a new video in the player 
    185    player.sendEvent('load','http://www.mysite.com/videos/bbb.mp4'); 
    186  
    187 Here's the full list of events you can send, plus their parameters: 
    188  
    189  
    190 .. describe:: ITEM ( index:Number ) 
    191  
    192    Start playback of a specific item in the playlist. If *index* isn't set, the current playlistitem will start. 
    193  
    194 .. describe:: LINK ( index:Number ) 
    195  
    196    Navigate to the *link* of a specific item in the playlist. If *index* is not set, the player will navigate to the link of the current playlistitem. 
    197  
    198 .. describe:: LOAD ( url:String ) 
    199  
    200    Load a new media file or playlist into the player. The *url* must always be sent. 
    201  
    202 .. describe:: MUTE ( state:Boolean ) 
    203  
    204    Mute or unmute the player's sound. If the *state* is not set, muting will be toggled. 
    205  
    206 .. describe:: NEXT 
    207  
    208    Jump to the next entry in the playlist.  No parameters. 
    209  
    210 .. describe:: PLAY ( state:Boolean ) 
    211  
    212    Play (set *state* to *true*) or pause (set *state* to *false*) playback. If the *state* is not set, the player will toggle playback. 
    213  
    214 .. describe:: PREV 
    215  
    216    Jump to the previous entry in the playlist.  No parameters. 
    217  
    218 .. describe:: SEEK ( position:Number ) 
    219  
    220    Seek to a certain position in the currently playing media file. The *position* must be in seconds (e.g. *65* for one minute and five seconds).  
    221  
    222    .. note:: 
    223  
    224       Seeking does not work if the player is in the *IDLE* state. Make sure to check the *state* variable before attempting to seek. Additionally, for the *video* media :ref:`provider <mediaformats>`, the player can only seek to portions of the video that are already loaded. Other media providers do not have this additional restriction. 
    225  
    226 .. describe:: STOP 
    227  
    228    Stop playback of the current playlist entry and unload it. The player will revert to the *IDLE* state and the poster image will be shown. No parameters. 
    229  
    230 .. describe:: VOLUME ( percentage:Number ) 
    231  
    232    Change the audio volume of the player to a certain percentage (e.g. *90*). If the player is muted, it will automatically be unmuted when a volume event is sent. 
    233  
    234 .. note::  
    235  
    236    Due to anti-phishing restrictions in the Adobe Flash runtime, it is not possible to enable/disable fullscreen playback of the player from JavaScript. 
    237  
    238 Setting listeners 
    239 ----------------- 
    240  
    241 In order to let JavaScript respond to player updates, you can assign listener functions to various events the player fires. An example of such event is the *VOLUME* event, when the volume of the player is changed. The player will call the listener function with one parameter, a *key:value* populated object that contains more info about the event. 
    242  
    243 In the naming of the listener functions, the internal architecture of the JW Player sines through a little. Internally, the player is built using a Mode-View-Controller design pattern: 
    244  
    245 * The *Model* takes care of the actual media playback. It sends events to the View. 
    246 * The *View* distributes all events from the Model to the plugins and API. It also collects all input from the plugins and API. 
    247 * The *Controller* receives and checks all events from the View. In turn, it sends events to the Model. 
    248  
    249 Basically, the events from the View are those you send out using the *sendEvent()* API function. With two other API functions, you can listen to events from the Model (playback updates) and Controller (control updates). These API functions are  *addModelListener()* and *addControllerListener()*. Here's a few examples: 
    250  
    251 .. code-block:: html 
    252  
    253    function stateTracker(obj) {  
    254       alert('the playback state is changed from '+obj.oldstate+' to '+obj.newstate); 
    255    }; 
    256    player.addModelListener("STATE","stateTracker"); 
    257  
    258    function volumeTracker(obj) { 
    259       alert('the audio volume is changed to: '+obj.percentage'+ percent'); 
    260    }; 
    261    player.addControllerListener("VOLUME","volumeTracker"); 
    262  
    263 If you only need to listen to a certain event for a limited amount of time (or just once), use the *removeModelListener()* and removeControllerListener()* functions to unsubscribe your listener function. The syntax is exactly the same: 
    264  
    265 .. code-block:: html 
    266  
    267    player.removeModelListener("STATE","stateTracker"); 
    268    player.removeControllerListener("VOLUME","volumeTracker"); 
    269  
    270 .. note::  
    271  
    272    You MUST string representations of a function for the function parameter! 
    273  
    274 Model events 
    275 ^^^^^^^^^^^^ 
    276  
    277 Here's an overview of all events the *Model* sends. Note that the data of every event contains the *id*, *version* and *client* parameters that are also sent on :ref:`playerReady <javascriptapi>`. 
    278  
    279 .. describe:: ERROR 
    280  
    281    Fired when a playback error occurs (e.g. when the video is not found or the stream is dropped). Data: 
    282  
    283    * *message* ( String ): the error message, e.g. *file not found*  or *no suiteable playback codec found*. 
    284  
    285 .. describe:: BUFFER 
    286  
    287    Fired when the player loads some media into its buffer. 
    288  
    289    * *percentage* ( Number ): The percentage (0-100) of seconds buffered versus the media's duration.  i.e. if the media is 60 seconds long, and half of the video has been buffered, a buffer event will be fired with percentage=50. 
    290  
    291 .. describe:: META 
    292  
    293    Fired when metadata on the currently playing media file is received. The exact metadata that is sent with this event varies per individual media file. Here are some examples: 
    294  
    295    * *duration* ( Number) : sent for *video*, *youtube*, *http* and *rtmp* media. In seconds. 
    296    * *height* ( Number ): sent for all media providers, except for *youtube*. In pixels. 
    297    * *width* ( Number ): sent for all media providers, except for *youtube*. In pixels. 
    298    * Codecs, framerate, seekpoints, channels: sent for *video*, *http* and *rtmp* media. 
    299    * TimedText, captions, cuepoints: additional metadata that is embedded at a certain position in the media file. Sent for *video*, *http* and *rtmp* media. 
    300    * ID3 info (genre, name, artist, track, year, comment): sent for MP3 files (the *sound* :ref:`media provider <mediaformats>`). 
    301  
    302  
    303    .. note::  
    304  
    305       Due to the :ref:`crossdomain` restrictions of Flash, you cannot load a ID3 data from an MP3 on one domain in a player on another domain. This issue can be circumvented by placing a *crossdomain.xml* file on the server that hosts your MP3s. 
    306  
    307 .. describe:: state 
    308  
    309    Fired when the playback state of the video changes. Data: 
    310  
    311    * *oldstate* ( 'IDLE','BUFFERING','PLAYING','PAUSED','COMPLETED' ): the previous playback state. 
    312    * *newstate* ( 'IDLE','BUFFERING','PLAYING','PAUSED','COMPLETED' ): the new playback state. 
    313  
    314    .. note::  
    315  
    316       You will not be able to check if a video is completed by polling for *getConfig().state*. The player will only be in the COMPLETED state for a very short time, before jumping to IDLE again. Always use *addModelListener('state',...)* if you want to check if a video is completed. 
    317  
    318 .. describe:: time 
    319  
    320    Fired when the playback position is changing (i.e. the media file is playing). It is fired with a resolution of 1/10 second, so there'll be a lot of events! Data: 
    321  
    322    * *duration* ( Number ): total duration of the media file in seconds, e.g. *150* for two and a half minutes. 
    323    * *position* ( Number ): current playback position in the file, in seconds. 
    324  
    325 Controller events 
    326 ^^^^^^^^^^^^^^^^^ 
    327  
    328 Here's an overview of all events the *Controller* sends. Note that the data of every event contains the *id*, *version* and *client* parameters that are also sent on :ref:`playerReady <javascriptapi>`. 
    329  
    330 .. describe:: ITEM 
    331  
    332    Fired when the player switches to a new playlist entry. The new item will immediately start playing. Data: 
    333  
    334   * *index* ( Number ): playlist index of the media file that starts playing. 
    335  
    336 .. describe:: MUTE 
    337  
    338    Fired when the player's audio is muted or unmuted. Data: 
    339  
    340    * *state* ( Boolean ): the new mute state. If *true*, the player is muted. 
    341   
    342 .. describe:: PLAY 
    343  
    344    Fired when the player toggles playback (playing/paused). Data: 
    345  
    346    * *state* ( Boolean ): the new playback state. If *true*, the player plays. If *false*, the player pauses. 
    347  
    348 .. describe:: PLAYLIST 
    349  
    350    Fired when a new playlist (a single file is also pushed as a playlist!) has been loaded into the player. Data: 
    351  
    352    * *playlist* ( Array ): The new playlist. It has exactly the same structure as the return of the *getPlaylist()* call. 
    353  
    354 .. describe:: RESIZE 
    355  
    356    Fired when the player is resized. This includes entering/leaving fullscreen mode. Data: 
    357  
    358    * *fullscreen* ( Boolean ): The new fullscreen state. If *true*, the player is in fullscreen. 
    359    * *height* ( Number ): The overall height of the player. 
    360    * *width* ( Number ): The overall width of the player. 
    361  
    362 .. describe:: SEEK 
    363  
    364    Fired when the player is seeking to a new position in the video/sound/image. Parameters: 
    365  
    366    * *position* ( Number ): the new position in the file, in seconds (e.g. *150* for two and a half minute). 
    367  
    368 .. describe:: STOP 
    369  
    370    Fired when the player stops loading and playing. The playback state will turn to *IDLE* and the position of a video will be set to 0. No data. 
    371  
    372 .. describe:: VOLUME 
    373  
    374    Fired when the volume level is changed. Data: 
    375  
    376    * *percentage* ( Number ): new volume percentage, from 0 to 100 (e.g. *90*). 
     285     
     286    <div id="container">Loading the player ...</div> 
     287     
     288    <script type="text/javascript"> 
     289        jwplayer("container").setup({ 
     290            flashplayer: "/jwplayer/jwplayer.swf", 
     291            file: "/uploads/video.mp4", 
     292            height: 270, 
     293            width: 480, 
     294            events: { 
     295                onVolume: function(event) {  
     296                    alert("the new volume is: "+event.volume); 
     297                } 
     298            } 
     299        }); 
     300    </script> 
     301 
     302 
     303And here's the full event list: 
     304 
     305.. describe:: onBufferChange(callback) 
     306 
     307    Fired when the currently playing item loads additional data into its buffer. Event attributes: 
     308 
     309    * **percent**: Number: Percentage (between 0 and 100); number of seconds buffered / duration in seconds. 
     310 
     311.. describe:: onBufferFull(callback) 
     312 
     313    Fired when the player's buffer has exceeded the player's bufferlength property (default: 1 second). No attributes. 
     314 
     315.. describe:: onError(callback) 
     316 
     317    Fired when an error has occurred in the player. Event attributes: 
     318 
     319    * **message**: String: The reason for the error. 
     320 
     321.. describe:: onFullscreen(callback) 
     322 
     323    Fired when the player's fullscreen mode changes. Event attributes: 
     324     
     325    * fullscreen: boolean. New fullscreen state. 
     326 
     327.. describe:: onMetadata(callback) 
     328 
     329    Fired when new metadata has been discovered in the player. Event attributes: 
     330 
     331    **data**: Object: dictionary object containing the new metadata.  
     332 
     333.. describe:: onMute(callback) 
     334 
     335    Fired when the player has gone into or out of the mute state. Event attributes:  
     336 
     337    * **mute**: Boolean: New mute state. 
     338 
     339.. describe:: onPlaylist(callback) 
     340 
     341    Fired when a new playlist has been loaded into the player. Event attributes:  
     342     
     343    * **playlist**: Array: The new playlist; an array of PlaylistItem objects. 
     344 
     345.. describe:: onPlaylistItem(callback) 
     346 
     347    Fired when the player is playing a new media item. Event attributes: 
     348 
     349    * **index** Number: Zero-based index into the playlist array (e.g. 0 is the first item). 
     350 
     351.. describe:: onReady(callback) 
     352 
     353    Fired when the player has initialized and is ready for playback. No attributes. 
     354 
     355.. describe:: onResize(callback) 
     356 
     357    Fired when the player's dimensions have changed (the player is resizing or switching fullscreen). Event attributes: 
     358 
     359    * **width**: Number: The new width of the player. 
     360    * **height**: Number: The new height of the player. 
     361 
     362.. describe:: onPlay(callback) 
     363 
     364    Fired when the player enters the *PLAYING* state. Event attributes: 
     365 
     366    * **oldstate**: String: the state the player moved from. Can be *PAUSED* or *BUFFERING*. 
     367 
     368.. describe:: onPause(callback) 
     369 
     370    Fired when the player enters the PAUSED state. Event attributes: 
     371 
     372    * **oldstate**: String: the state the player moved from. Can be *PLAYING* or *BUFFERING*. 
     373 
     374.. describe:: onBuffer(callback) 
     375 
     376    Fired when the player enters the BUFFERING state. Event attributes: 
     377 
     378    * **oldstate**: String: the state the player moved from. Can be *PLAYING*, *PAUSED* or *IDLE*. 
     379 
     380.. describe:: onIdle(callback) 
     381 
     382    Fired when the player enters the IDLE state. Event attributes: 
     383 
     384    * **oldstate**: String: the state the player moved from. Can be *PLAYING*, *PAUSED* or *BUFFERING*. 
     385 
     386.. describe:: onComplete(callback) 
     387 
     388    Fired when the player has finished playing the current media. No event attributes. 
     389 
     390.. describe:: onPosition(callback) 
     391 
     392    When the player is playing, fired as the playback position gets updated. This happens with a resolution of 0.1 second, so there's a lot of events! Event attributes: 
     393 
     394    * **duration**: Number: Duration of the current item in seconds. 
     395    * **offset**: Number: When playing streaming media, this value contains the last unbuffered seek offset. 
     396    * **position**: Number: Playback position in seconds. 
     397 
     398.. describe:: onVolume(callback) 
     399 
     400    Fired when the player's volume changes. Event attributes: 
     401 
     402    * **volume**: Number: The new volume percentage (0 to 100). 
     403 
     404 
     405 
     406Chaining 
     407-------- 
     408 
     409Note that every API call to a JW Player in turn returns the player instance. This makes it possible to chain API calls  (like with `jQuery <http://jquery.net>`_): 
     410 
     411.. code-block:: javascript 
     412 
     413    jwplayer().setVolume(50).onComplete(function(){ alert("done!"); }).play(); 
     414 
     415 
Note: See TracChangeset for help on using the changeset viewer.