DynTube API
  • Welcome!
  • Key Concepts
  • Quick Start
  • Reference
    • Videos
      • Video Upload via File (Server Side)
      • Video Upload via URL (server side)
      • HTML-Form Client Side Video Uploads
      • Get Video Status
      • Get Videos
      • Get Video
      • Update Video
      • Delete Video
      • Download Original Video
      • Get Video for Mobile App/Custom Player
      • Update Video Image
      • Add Video Captions/Chapters/Subtitles
      • Delete Video Captions/Subtitles/Chapters
      • Create Expirable Links
      • Get Collected Emails
      • Setting Up Webhooks
      • Copy call-to-action (CTA) to Videos
      • Token Authentication
    • Projects
      • Create Project
      • Update a Project
      • Get Projects
      • Get a Project
      • Delete a Project
      • Set default CTA for Project
    • Live Streaming
      • Create a Live Stream
      • Update a Live Stream
      • Get Live Streams
      • Get a Live Stream
      • Count Live Streams
      • Live Streams Limit
      • Get Live Streaming Recording
      • Delete a Live Stream
      • Service and Regions for live streams
    • Channels
      • Get Channels
      • Get Channel
      • Delete Channel
    • Subscriptions
      • Create a Plan
      • Create a Member
      • Attach Plan To Member
      • Get Plans
      • Get Members
      • Get Member's Plans
      • Delete a Plan
    • Analytics
      • Use your User Ids in Analytics
      • Get Video Analytics
    • Javascript Events Methods
      • Plain Javascript Events & Methods
      • Control the Player using React
      • Control the Player in Vue.js
    • Developer Resources
      • How to embed DynTube player in Next.Js
      • How to embed the video player in React
      • How to play DynTube videos in React Native
      • ExoPlayer app to play HLS videos
      • How to embed videos & channels dynamically
      • How to Import Vimeo Videos into DynTube
Powered by GitBook
On this page
  1. Reference
  2. Developer Resources

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_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/player_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
  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);
playerView.setPlayer(player);
  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:

player.setMediaSource(mediaSource);
player.prepare();
  1. Start the video playback:

player.setPlayWhenReady(true);
PreviousHow to play DynTube videos in React NativeNextHow to embed videos & channels dynamically

Last updated 2 years ago