Set up a player (FireTV)
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:
- 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" />
- In app/java/MainActivity.java, set your license key.
new LicenseUtil().setLicenseKey(this, "YOUR_LICENSE_KEY");
- Get a reference to the player.
JWPlayerView playerView = findViewById(R.id.jwplayerview);
JWPlayer mPlayer = mPlayerView.getPlayer();
- Use
PlaylistItem.Builder()to create and define aPlaylistItemobject.
For videos hosted with JWP, use the following steps to retrieve the URL of a video:
- Click the name of the video in your JWP dashboard Media Library.
- Under Media Summary, click the View Assets.
- On the Video Renditions tab in the row of a specific rendition, click ∨ to reveal the DIRECT URL.
- Copy the DIRECT URL.
- 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();
- Create a
List<PlaylistItem>object. Add thePlaylistItemobject to theList<PlaylistItem>object.
List<PlaylistItem> playlist = new ArrayList<>();
playlist.add(playlistItem);
- Use
PlayerConfig.Builder()to create aPlayerConfigobject. Assign theList<PlaylistItem>object to the playlist property of thePlayerConfigobject.
PlayerConfig config = new PlayerConfig.Builder()
.playlist(playlist)
.build();
- Set up
mPlayerwith thePlayerConfigobject.
mPlayer.setup(config);
Updated almost 2 years ago
