Set up a player (Android v4 | Fire TV)

Add a player in your Android app or Fire TV project.





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

💡

If you have unique implementation requirements, please contact your JWP representative.



Implementation

Use the following steps and code examples to add the JWPlayerView to the app/res/layout/activity_main.xml and app/java/MainActivity.java files of your app:

  1. In app/res/layout/activity_main.xml, add the JWPlayerView.
<com.jwplayer.pub.view.JWPlayerView
   android:id="@+id/jwplayerview"
   android:layout_width="match_parent"
   android:layout_height="match_parent" />
<com.jwplayer.pub.view.JWPlayerView
   android:id="@+id/firetv_player"
   android:layout_width="match_parent"
   android:layout_height="match_parent" />
  1. In app/java/MainActivity.java, set your license key.
new LicenseUtil().setLicenseKey(this, "YOUR_LICENSE_KEY");

  1. Get a reference to the player.
JWPlayerView playerView = findViewById(R.id.jwplayerview);
JWPlayer mPlayer = mPlayerView.getPlayer();

  1. Use PlaylistItem.Builder() to create and define a PlaylistItem object.

💡

For videos hosted with JWP, use the following steps to retrieve the URL of a video:

  1. Click the name of the video in your JWP dashboard Media Library.
  2. Under Media Summary, click the View Assets.
  3. On the Video Renditions tab in the row of a specific rendition, click to reveal the DIRECT URL.
  4. Copy the DIRECT URL.
  5. Click Close.

Hosting your videos with JWP enables you to query the Analytics API to access SDK video metrics.

PlaylistItem playlistItem = new PlaylistItem.Builder()
        .file("https://cdn.jwplayer.com/manifests/{MEDIA_ID}.m3u8")
        .build();

  1. Create a List<PlaylistItem> object. Add the PlaylistItem object to the List<PlaylistItem> object.
List<PlaylistItem> playlist = new ArrayList<>();
playlist.add(playlistItem);

  1. Use PlayerConfig.Builder() to create a PlayerConfig object. Assign the List<PlaylistItem> object to the playlist property of the PlayerConfig object.
PlayerConfig config = new PlayerConfig.Builder()
       .playlist(playlist)
       .build();

  1. Set up mPlayer with the PlayerConfig object.
mPlayer.setup(config);