You are here

public function OSMPlayer::getPlayerJS in MediaFront 6.2

Same name and namespace in other branches
  1. 6 players/osmplayer/player/OSMPlayer.php \OSMPlayer::getPlayerJS()
  2. 7 players/osmplayer/player/OSMPlayer.php \OSMPlayer::getPlayerJS()

Returns the javascript to add the player to the page.

1 call to OSMPlayer::getPlayerJS()
OSMPlayer::getJS in players/osmplayer/player/OSMPlayer.php
Returns the JavaScript code to add and instantiate the player on the page.

File

players/osmplayer/player/OSMPlayer.php, line 484

Class

OSMPlayer
PHP wrapper class for the Open Standard Media (OSM) player.

Code

public function getPlayerJS() {
  $playerId = $this
    ->getId();
  $params = $this
    ->getParams();

  // Create the player in javascript.
  $js = 'var ' . $playerId . ' = jQuery("#' . $playerId . '").mediaplayer({' . implode(',', $params) . '});';

  // Now that the player has made it's way through the loading process... hide the busy cursor.
  $js .= 'jQuery("#' . $playerId . '_loading").hide();';

  // Now add our playlist connections to the javascript.
  foreach ($this->playlists as $playlist) {
    $js .= 'jQuery.media.addPlaylist("' . $playlist . '",' . $playerId . ');';
  }

  // Now add our controller connections to the javascript.
  foreach ($this->controllers as $controller) {
    $js .= 'jQuery.media.addController("' . $controller . '",' . $playerId . ');';
  }

  // Return the script.
  // We need to use setTimeout since some browsers jump the gun on when they are really ready.
  return 'jQuery(function() { setTimeout( function() {' . $js . '}, 10 ); });';
}