Controllers (Deprecated)

The controller code sample provides an initial template for handling client requests and work.

Note: Ooyala Player V3 has been deprecated and is scheduled to be disabled. For details and alternatives, see the OVP Release Notes.
For this code sample, the controller code handles the server side processing of Cross-Device Resume, Google IMA, and Ooyala Player Token authentication features. The controller code runs in the server side PHP CodeIgniter framework.

In addition to defining the functions to handle the features, such as secure token, the controller code:

  • Loads the Ooyala library
  • Loads the Ooyala configuration file
  • Loads an Ooyala wrapper
  • Loads some variables defined in the Ooyala library
  • Creates a new instance of the Ooyala player <>
  • Runs the example in the Ooyala PHP SDK

The controller code also handles Cross-Device Resume, Google IMA, Ooyala Player Token features and the Player V3 message bus.

Where to Find the Code

The controller code is located in the application directory. To get to this code in our GitHub repository, use the URL: https://github.com/ooyala/code-samples/tree/master/application/controllers.

Routes and Functions

In the secure_xdr_googleima.php controller code file, the name of the class is the name of the general route and each function (expect _contruct) is a route.

For example, if we have the following routes:

localhost/index.php/Secure_XDR_GoogleIMA/token 
localhost/index.php/Secure_XDR_GoogleIMA/google_ima
and we have the following class in the controller folder:
class Secure_XDR_Google_IMA{
      function player_token {
        // ...
      }

      function XDR {
        // ...
      }
    }

Then each route following the base path (localhost/index.php) is the name of a controller, and each route following the controller is the name of a function inside that controller. 

Route Description
Secure_XDR_GoogleIMA/cross_resume Cross device resume
Secure_XDR_GoogleIMA/simple Simple player
Secure_XDR_GoogleIMA/message_bus Simple message bus handling
Secure_XDR_GoogleIMA/message_bus_advanced Milestones with message bus
Secure_XDR_GoogleIMA/token An example with playerToken
Secure_XDR_GoogleIMA/google_ima Player with Google IMA enabled
Secure_XDR_GoogleIMA/multi_feature An example that has all of the above
Web_example/ A simple client page that shows a video with trending and related videos
Web_example/mobile The same as Web_example root but with page resizing

Controller Functions and Views

To get a better idea about how the controller handles the requests and work for the views, lets look at one of the functions in the controller code in detail. In the following code snippet, the route localhost/index.php/Secure_XDR_GoogleIMA/cross_resume has a corresponding class in the controller code, public function cross_resume( ) {. This function includes a data array that includes information about the player that you would expect, such as the default_player_id and the embed code. Other elements of the array that are specific to the Cross Device Resume feature include getting the playhead time, loading a user_id, and loading the Cross Device resume view.
    public function cross_resume(){
            $data['player_id'] = $this->_default_player_id;
            $embed_code = $this->_default_embed_code;
            $data['embed_code'] = $embed_code;
            $user_id = $this->_sample_email;
            $embed_token_url = $this->_api_wrapper->get_embed_token($embed_code, $user_id);
            $data['embed_token_url'] = $embed_token_url;
            $playhead_time = $this->_api_wrapper->get_playhead_time($embed_code, $user_id);
            $data['playhead_time'] = $playhead_time;
            $this->load->view('cross_resume', $data);

The corresponding web page view, located in the repository as codesamples/applications/views/cross_resume.php, looks like this:

 <!DOCTYPE html>
<html>
 <head>
   <script src="http://player.ooyala.com/v3/<?php echo $player_id; ?>"></script>
  </head>
  <body>
     <h1>Cross resume example</h1>
     <div id='playerwrapper' style='width:920px;height:400px;'></div>
     <script>
         var playheadTime = <?php echo $playhead_time;?>;
var videoPlayer =
OO.Player.create('playerwrapper','<?php echo $embed_code; ?>', {
embedToken: '<?php echo $embed_token_url; ?>',
initialTime: playheadTime
});
</script>
</body>
</html>

Loading Views

For each public function with a corresponding view, the views are loaded with a $this->load->view('file-name', $data) where $data is an optional array that has useful variables for the view. For example, the Cross Device Resume View is loaded with the following statement in the controller code:

$this->load->view('cross_resume', $data);

The controller code contains the following functions that have corresponding views:

Controller function Corresponding View
public function cross_resume() Cross device resume
public function simple() Simple player
public function message_bus() Message Bus
public function message_bus_advanced() Message Bus Advanced
public function player_token() Ooyala Player Token
public function google_ima() Google IMA
If we wanted to see the server and views working, we might go to a URL similar to the following: insert_your_server_name.com/Secure_XDR_GoogleIMA/multi_feature.

To get the full picture of what is happening in each route, be sure to check the views.

해당 내용이 도움 되었습니까?