Portal Berita dan Informasi Terbaik di Indonesia

Lets Dive into Exo-Player (Part I) | by Prateek Batra

What is Exo-Player?

ExoPlayer is an application-level media player for Android. It’s an alternative to Android’s Original MediaPlayer for playing audio and video both locally and over the Internet along with support for many Adaptive & Progressive Streaming and support for subtitles, multiple audio support …etc

ExoPlayer Whole Media Support

Some Basic History & Overview (Back to where it all started)

Before Exo-Player came into existence there was an Android multimedia framework with which one can easily integrate & play audio or video from media files stored in your application’s resources (raw resources), from standalone files in the filesystem, or from a data stream arriving over a network connection, all using MediaPlayer APIs.

Exo-Player made an official release in Google I/O 2017
Since we are not getting here on deep you can watch the video

What is Progressive Streaming?

Progressive Streaming is a video streaming mechanism in which we basically have a single mp4 file that is streamed on every device and overall the different internet speed

What is Adaptive Streaming?

Adaptive Streaming is a video streaming mechanism in which whenever we play any resource it will automatically adapt itself on basis of resolution and streaming speed.

In adaptive streaming, there is different video size and quality based on screen resolution and internet speed while is not so in Progressive streaming.

Gradle Dependency

In your project module Gradle make sure you have :

allprojects {
repositories {
google()
jcenter()
}
}

In your app module Gradle add :

This is the main dependency for exo-player implementation but in case you want to use some of its specific feature you can use as follow

implementation 'com.google.android.exoplayer:exoplayer:2.X.X'For core functionalities(exoplayer-core:2.X.X)//Required
For DASH Support (exoplayer-dash:2.X.X)
For HLS Support (exoplayer-hls:2.X.X)
For Smooth Streaming Support (exoplayer-smoothstreaming:2.X.X)
For UI components and resources Support (exoplayer-ui:2.X.X)

The latest one is 2.12.0
* This is recommended as we will be using the latest Styled Player View along with this in our demo project

Also, keep in mind to add this :

android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

UI Part

Now coming to User Interface we will be using the default StyledPlayerView, StyledPlayerControlView that comes along with the latest version of Exo-player

Add as follow in the XML file of your activity

Now let’s come to the logic & initialization
First, we need to create, initialize & set our player with the media source we want along with the after based on our activity lifecycle we can release/reinitialize our player

Simple Exo-Player: This is a wrapper that is our player

Data Source Factory: This is a Factory data reader for our data source i.e which can be any file, asset, https…etc each of our media sources requires a data source factory

Media Source: This defines, provides & loads the media to be played by our Player. Now Based on our media type we have a different types of media sources like HLS Media Source, Progressive Media Source(earlier used Extractor Media Source), Smooth Streaming Media Source..etc.

Well, we don’t need to worry about the thread but for the information,

Exo-Player is accessed from the main thread but for any of its internal working operations like buffering, preparing, or playing files for theses it has an internal playback thread that uses a classic thread and handler mechanism in which when we operate on our player (for example a seek) a message is delivered to the internal playback thread via a message queue and vice versa a message is delivered to our main thread on any playback event

With the UI you can try to these configs

With the new Styled UI, it has solved our many problems like
Now we don’t need to add speed control, Subtitle, Audio manual now Also we have a very decent UI with much new functionality as compared to the previous one.

But still, there will be cases when we need to have a custom UI functionality along with that we need to add multiple video quality support
Do give claps and comments to motivate me to write another article specifically for all these things.

Do check out this awesome code lab by google:



Source by [author_name]

Leave a Reply

Your email address will not be published.