Set up the MediaPlayer

The MediaPlayer interface for Android encapsulates the functionality and behavior of a media player.

TVSDK provides one implementation of the MediaPlayer interface, the DefaultMediaPlayer class. When you need video playback functionality, instantiate DefaultMediaPlayer.

TIP

Interact with the DefaultMediaPlayer instance only with the methods that are exposed by the MediaPlayer interface.

  1. Instantiate a MediaPlayer using the public DefaultMediaPlayer.create factory method, passing a Java Android application context object.

    public static MediaPlayer create(Context context) 
    
    
  2. Call MediaPlayer.getView to get a reference to the MediaPlayerView instance.

    MediaPlayerView getView() throws IllegalStateException; 
    
    
  3. Place the MediaPlayerView instance in a FrameLayout instance, which places the video on the device’s screen.

    FrameLayout playerFrame = (FrameLayout) view.findViewById(R.id.playerFrame); 
    playerFrame.addView(mediaPlayer.getView()); 
    
    

The MediaPlayer instance is now available and properly configured to display video content on the device screen.

On this page