ExoPlayer app to play HLS videos

To create an ExoPlayer demo app to play HLS videos, you can follow the steps below:

  1. Create a new Android project in Android Studio.

  2. Add the ExoPlayer library to your project by adding the following dependency to your app's build.gradle file:

implementation 'com.google.android.exoplayer:exoplayer:2.16.0'
  1. Create a layout file for your video player activity. Here's an example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_height="match_parent" />

  1. In your activity's onCreate method, initialize the ExoPlayer and set the player's view:

// Initialize the ExoPlayer
SimpleExoPlayer player = new SimpleExoPlayer.Builder(this).build();

// Set the player's view
PlayerView playerView = findViewById(R.id.player_view);
  1. Create a MediaSource object to represent your HLS video stream. Here's an example:

// Create a MediaSource object for the HLS video stream
String videoUrl = "https://endpoint.dyntube.com/video.m3u8";
Uri uri = Uri.parse(videoUrl);
MediaSource mediaSource = new HlsMediaSource.Factory(
        new DefaultDataSourceFactory(this, "exoplayer-demo")).createMediaSource(uri);

Note that in this example, the HLS video stream is hosted at https://endpoint.dyntube.com/video.m3u8. You should replace this URL with the URL for your own video stream.

  1. Set the MediaSource on the ExoPlayer:

  1. Start the video playback:


Last updated