In the last article (Lets Dive into ExoPlayer ) we started with the basic setup of ExoPlayer using Styled Player View.
Now in the article i tried penning down the part in which we will set up configuration in ExoPlayer to extract multiple quality from a video so that user can switch between them
The basic definition of bitrate is “the number of bits that are conveyed or processed in a given unit of time”
Now let’s think of it this way we have a video file now it has certain bits of data embedded inside it.These bits of data may or may not be available in multiple bitrates
In case it doesn’t have multiple bitrates (MP4 File)
In case it has Multiple Bitrate (HLS, DASH)
Now there can be many cases but we are considering these specifically
ExoPlayer provide support to play all such different kind of video format
HTTP-based adaptive bitrate streaming communications protocol was developed by Apple Inc. and released in 2009. It works by breaking the overall stream into a sequence of small HTTP-based files i.e short chunk of a whole file. A list of available streams encoded at different bit rates and then can be used to play as m3u8 file format.
This is a kind of media streaming protocol that works similarly to the way HLS works by breaking the content into a sequence of small segments, which are served over HTTP. It can be a movie or the live broadcast of a sports event.
DASH was developed by MPEG (Moving Pictures Expert Group), the preeminent international authority for media compression.
The format for a dash file is MPD and because it is open source and support Encrypted Media Extensions (EME) and Media Source Extension (MSE) it is widely used for DRM Support too
The content made available by both protocols has a variety of different bit rates. and we can use a bit rate adaptation (ABR) algorithm to automatically select the segment with the highest bit rate possible based on bandwidth and other factors
ExoPlayer has support for the ABR Algorithm which is basically a one of the bandwidth based bitrate selection Algorithm that automatically chooses the best bitrate to select and play
There are various other algorithms: Adaptive, Random, and Fixed Track Selection.
Similarly we have different quality of the same video embedded in it using bitrate there can be embedded subtitles , and audio just as we have in dubbed/subbed videos
Basic Setup :
Demo Repo :
Since we have already setup our player in here will be skipping that
In ExoPlayer every thing is a track whether it is a Video, Audio ,Text
TrackSelector : We will be using ExoPlayer Default TrackSelector this will basically helps us get the currently selected track and extract all it info
A single track can have multiple embedded sub tracks inside it i.e track-groups
val trackSelector = DefaultTrackSelector(/* context= */this, AdaptiveTrackSelection.Factory())val player = ExoPlayer.Builder(this)
Basically this will help us with extracting all the defined Sub Track that are embedded in the main parent track that can be follow type TRACK_TYPE_VIDEO, TRACK_TYPE_AUDIO, TRACK_TYPE_TEXT, TRACK_TYPE_METADATA, TRACK_TYPE_IMAGE .etc
Since Using the Styled Player Viewer we get subtitle, audio selection by default we will focus on video quality only here
Generate Quality List is a Kotlin extension function that basically generates all Video Quality Levels Here we have a
Render Track that defines all the track info of current media source
Now Render Track have various track group of type Audio, Video,Text ..etc
These Track Group consist of multiple video quality tracks which we will check one by one for support i.e whether they are supported or not
If that video quality track is supported then we will extract the label from it and use that track further with our player to set that quality
Here we are using TrackSelectionOverrides that can be used with Track Selector to select that particular track
Now this function will return us a list where we have each element paired up to its SelectionOverride we can parse that list anywhere and show quality
Here is the function which is being used above to check for support