Set up a player (Android)

Add a player in your Android app.


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" />
    
  2. In app/java/MainActivity.java, set your license key.

    new LicenseUtil().setLicenseKey(this, "YOUR_LICENSE_KEY");
    
  3. Get a reference to the player.

    JWPlayerView playerView = findViewById(R.id.jwplayerview);
    JWPlayer mPlayer = mPlayerView.getPlayer();
    
  4. 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);
    
  2. 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();
    
  3. Set up mPlayer with the PlayerConfig object.

    mPlayer.setup(config);
    


© 2007-2024 Longtail Ad Solutions, Inc.