ExoPlayer app to play HLS videos

To create an ExoPlayer demo app to play HLS videos, you can follow the steps below:
  1. 1.
    Create a new Android project in Android Studio.
  2. 2.
    Add the ExoPlayer library to your project by adding the following dependency to your app's build.gradle file:
implementation ''
  1. 3.
    Create a layout file for your video player activity. Here's an example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
android:layout_height="match_parent" />
  1. 4.
    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(;
  1. 5.
    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 = "";
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 You should replace this URL with the URL for your own video stream.
  1. 6.
    Set the MediaSource on the ExoPlayer:
  1. 7.
    Start the video playback: