Last Updated: March 14, 2019

The JWPlayerView is the central UI component of our SDK. This class allows you to easily load new media into the player, manage video and audio playback via the Playback API and register multiple event listeners that could help you with custom analytics or error handling.

Adding a JWPlayerView to your XML layout

The JWPlayerView is available in the Graphical Layout Editor of Android Studio by navigating to Custom > Custom Views in your palette.

You can also add the view to your layout by adding these lines to your XML layout


An important thing to notice here is the jwp namespace. It allows you to setup your player with default settings such as autostart, file, repeat and more. For a full list of available options have a look at our XML options page.

Once you have the JWPlayerView in your layout, you can now get a reference to it by using findViewById().

     JWPlayerView playerView = (JWPlayerView) findViewById(R.id.playerView);

Instantiating a JWPlayerView programmatically

Instead of adding the JWPlayerView to your XML layout, you may also choose to programmatically instantiate it at any point.

Programmatic instantiation requires you to build a PlayerConfig first. The PlayerConfig tells the player which features you'd like to setup with.

PlayerConfig playerConfig = new PlayerConfig.Builder()

After instantiating the PlayerConfig you can then construct a JWPlayerView

JWPlayerView playerView = new JWPlayerView(context, playerConfig);

Finally, you must add the JWPlayerView to a ViewGroup

ViewGroup jwPlayerViewContainer = (ViewGroup) findViewById(R.id.jwPlayerContainer);

Activity Lifecycle Handling

In order to properly handle the Activity Lifecycle and release the player from memory when necessary, you must override the following methods of the Activity containing the JWPlayerView:

  • onDestroy()
  • onPause()
  • onResume()
  • onStart()
  • onStop()
protected void onStart() {

protected void onResume() {
    // Let JW Player know that the app has returned from the background

protected void onPause() {
    // Let JW Player know that the app is going to the background

protected void onStop() {

protected void onDestroy() {
    // Let JW Player know that the app is being destroyed
This configuration is not necessary when using JWPlayerFragment or JWPlayerSupportFragment since we already handle the lifecycle methods in those scenarios.

Orientation Changes and Fullscreen Handling

Handling orientation changes to enter fullscreen is fairly simple.

We begin by overriding the onConfigurationChanged() method of the Activity containing the player and setting the player to fullscreen whenever the device is in landscape.

public void onConfigurationChanged(Configuration newConfig) {
    // Set fullscreen when the device is rotated to landscape
    playerView.setFullscreen(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE, true);

Next, it is good practice to override the onKeyDown() method as well. This allow users to exit fullscreen whenever the back button is pressed.

public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Exit fullscreen when the user pressed the Back button
    if (keyCode == KeyEvent.KEYCODE_BACK) {
       if (playerView.getFullscreen()) {
           playerView.setFullscreen(false, false);
           return false;
    return super.onKeyDown(keyCode, event);

Lastly, you'll want to implement the VideoPlayerEvents.OnFullscreenListener on your Activity to receive a callback whenever the player is going to fullscreen. At that moment, you may need to hide the ActionBar and set any custom UI elements back to visible.

public void onFullscreen(boolean state) {
    if (state) {
    } else {

        If the root layout of this activity is the coordinator layout (default for new projects created in Android Studio 2.0+)
        Then we also want to unset fitsSystemWindows

Fullscreen in ListView or RecyclerView

Due to the way ListView and RecyclerView manage their own pools of views, we do not currently support fullscreen for players that are inside a ListView or RecyclerView. We recommend that you disable fullscreen by setting up the player to use a FullscreenHandler that does not perform any actions.

For example:

FullscreenHandler fullscreenDisabledHandler = new FullscreenHandler() {
  public void onFullscreenRequested() {


  public void onFullscreenExitRequested() {


  public void onResume() {

  public void onPause() {


  public void onDestroy() {


  public void onAllowRotationChanged(boolean allowRotation) {


  public void updateLayoutParams(ViewGroup.LayoutParams layoutParams) {


  public void setUseFullscreenLayoutFlags(boolean flags) {



If you need fullscreen in your application, a good pattern to follow is to have a single player instance outside the RecyclerView or ListView and use the RecyclerView/ListView to display thumbnails of your content.