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:
-
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"
-
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>
- In the MainActivity.java file, locate the
onCreate()
function. -
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);
-
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.