support Contact Support | system status System Status
Page Contents

    HLS Playback with the Native SDK for Android

    In this topic, you will learn how to play HLS content using the Native SDK for Android.

    Introduction

    The Brightcove Player SDK for Android supports and solves many issues around playing HTTP Live Streaming (HLS) videos on Android devices.

    Built on top of Google's ExoPlayer library, this is a good choice for playing HLS videos.

    Features:

    • Supports HTTP Live Streaming (HLS)
    • Supports IMA, VMAP, and FreeWheel mid-rolls with HLS streams
    • Supports HLS live streams
    • Supports advertising and analytics
    • Easily add custom plugins
    • No extra cost

    Limitations:

    • Only supported with Android 4.1 (JELLY_BEAN) and newer

    Implementing the player

    To use the HLS playback integration with the Player SDK, follow these steps:

    1. In your project's build.gradle file, add the following dependency: (use the latest version of the Native SDK)

      implementation "com.brightcove.player:exoplayer2:6.11.0"
    2. In your project's XML layout file, use the following video view:

      com.brightcove.player.view.BrightcoveExoPlayerVideoView

      Your XML layout file should look similar to this:

      <?xml version="1.0" encoding="utf-8"?>
        <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.brightcove.playvideos.MainActivity">
      
        <com.brightcove.player.view.BrightcoveExoPlayerVideoView
            android:id="@+id/brightcove_video_view"
            android:layout_width="match_parent"
            android:layout_height="280dp"
            android:layout_gravity="center_horizontal|top"/>
        </android.support.constraint.ConstraintLayout>
    3. In the MainActivity.java file, locate the onCreate() function.
    4. Below any existing code in the function, create an instance of BrightcoveExoPlayerVideoView and associate it with the layout using the following:

      public class MainActivity extends BrightcovePlayer {
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              setContentView(R.layout.activity_main);
              brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
              super.onCreate(savedInstanceState);
    5. For detailed steps, see the Build an App using the Brightcove Native SDK for Android document.

      You can also view code in the Brightcove ExoPlayer code samples.


    Page last updated on 28 Sep 2020