Working with Events

Learn how to extend the Activity object to include Ooyala notifications.

  1. Implement the Observer object in your Activity. For example:
    public class OoyalaAndroidTestAppActivity extends Activity implements OnClickListener, Observer  
  2. Attach your activity to the player, like this:
     player.addObserver(this);
  3. Implement the update method in the Activity:
    @Override
            public void update(Observable arg0, Object arg1) {
            Log.d(TAG, "Notification Recieved: " + arg1 + " - state: " + player.getState());
            if (arg1 == OoyalaPlayer.CONTENT_TREE_READY_NOTIFICATION) {
            metadataReady = true;
            Log.d(TAG, "AD - metadata true!");
            } else if (arg1 == OoyalaPlayer.METADATA_READY_NOTIFICATION) {
            Log.d(TAG, "Woot, here is the current metadata: " + player.getMetadata());
            }
            // if (((String)arg1).equals(OoyalaPlayer.STATE_CHANGED_NOTIFICATION) && ((OoyalaPlayer)arg0).getState()
            // == State.READY) {
            // player.play();
            // }
            }
    • arg0 is always the player instance
    • arg1 is the notification
The following notifications are defined as part of the OoyalaPlayer class:
 public static final String TIME_CHANGED_NOTIFICATION = "timeChanged";
 public static final String STATE_CHANGED_NOTIFICATION = "stateChanged";
 public static final String BUFFER_CHANGED_NOTIFICATION = "bufferChanged";
 public static final String CONTENT_TREE_READY_NOTIFICATION = "contentTreeReady";
 public static final String AUTHORIZATION_READY_NOTIFICATION = "authorizationReady";
 public static final String ERROR_NOTIFICATION = "error";
 public static final String PLAY_STARTED_NOTIFICATION = "playStarted";
 public static final String PLAY_COMPLETED_NOTIFICATION = "playCompleted";
 public static final String CURRENT_ITEM_CHANGED_NOTIFICATION = "currentItemChanged";
 public static final String AD_STARTED_NOTIFICATION = "adStarted";
 public static final String AD_COMPLETED_NOTIFICATION = "adCompleted";
 public static final String AD_SKIPPED_NOTIFICATION = "adSkipped";
 public static final String AD_ERROR_NOTIFICATION = "adError";
 public static final String METADATA_READY_NOTIFICATION = "metadataReady"; 
 public static final String SEEK_COMPLETED_NOTIFICATION = "seekCompleted"; 

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