Android: Understanding the BrightcovePlayer Class

In this topic, you will learn about the BrightcovePlayer class and how it provides basic lifecycle management.

BrightcovePlayer class

The BrightcovePlayer class resides in the core Brightcove SDK for Android and extends Android's Activity class.

As a basic Activity, the BrightcovePlayer class wraps a BrightcoveExoPlayerVideoView and sets up an EventLogger and default MediaController. It implements basic lifecycle management and full screen logic. It is meant to be subclassed.

public class MainActivity extends BrightcovePlayer {
...
}

At a minimum the onCreate() method should be overridden with logic to wire up the BrightcoveExoPlayerVideoView variable to the layout.xml file. For example:

brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);

For implementation details, see the BasicSampleApp code sample.

Support library components

If you choose not to use the BrightcovePlayer class, the BrightcovePlayerActivity and BrightcovePlayerFragment classes are available to you. To use either of these classes, you need to include the appcompat plugin in your build.gradle file as follows:

implementation "com.brightcove.player:android-appcompat-plugin:${anpVersion}"

BrightcovePlayerFragment class

The BrightcovePlayerFragment class extends the android.support.v4.app.Fragment class.

If you want to combine the Brightcove Player with other design elements in your layout, you can use the BrightcovePlayerFragment class. This is useful when designing for a tablet or larger screen, which has more room to combine UI components. For example, with a tablet, you could display multiple fragments at the same time, both living within the same activity.

public class MainFragment extends BrightcovePlayerFragment {
...
}

The onCreateView() should be extended to wire up the fragment's layout to the baseVideoView instance variable before calling super.onCreateView().

baseVideoView = (BaseVideoView) result.findViewById(R.id.brightcove_video_view);

For implementation details, see the AppCompatFragmentSampleApp code sample.

BrightcovePlayerActivity class

The BrightcovePlayerActivity class extends the android.support.v7.app.AppCompatActivity class.

If you choose to use an Activity, you can use the BrightcovePlayerActivity class.

public class MainActivity extends BrightcovePlayerActivity {
...
}

For implementation details, see the AppCompatActivitySampleApp code sample.

Lifecycle management

It is best practice to start with either the BrightcovePlayer activity or the BrightcovePlayerFragment, since these provide default lifecycle management implementation, including the following:

  • When a user pauses the app, the class keeps track of where they stopped.
  • When your app comes back from the background, the class remembers whether the video was playing or not, and restart playback where it left off.
  • If your app is killed due to memory issues, the class will seek to time in video to where it was.
  • An event logger is setup, which logs all events to logcat. This can be helpful for debugging.
  • The class dispatches events to communicate with plugins.
 

Now that you have an activity, you are ready to choose a video view, as detailed in the next document.