Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExoPlayer HlsMediaSource() deprecated

The HlsMediaSource() method is deprecated (I'm currently on exoplayer:2.6.1). What is the recommended method to use for HLS-media instead?

like image 244
Algar Avatar asked Jan 30 '18 10:01

Algar


Video Answer


2 Answers

After digging into the source code I concluded that

HlsMediaSource.Factory(dataFactory).createMediaSource(mediaUri)

is the way to go.

Edit: Expanding on the other factories

The factory pattern is also the recommended way to instantiate ExtractorMediaSource, SsMediaSource, DashMediaSource, and SingleSampleMediaSource as per the 2.6.1 release notes.

The factory methods simplifies MediaSource instantiation, especially in cases when you wish to configure optional parameters whilst leaving others set to their default values, e.g.

DashMediaSource.Factory(chunkSourceFactory, manifestDataSourceFactory)
    .setManifestParser(new CustomManifestParser())
    .createMediaSource(manifestUri, eventHandler, eventListener)
like image 138
Algar Avatar answered Oct 21 '22 04:10

Algar


If you cannot find HlsMediaSource you will need to add one more dependency:

implementation "com.google.android.exoplayer:exoplayer-hls:$exoplayer_version"

To implement it we need to have code similar to this:

val userAgent = Util.getUserAgent(context, USER_AGENT)

DefaultDataSourceFactory(
                context,
                userAgent
            )

val source = "https://some_url_link"
val uri = source.toUri()

HlsMediaSource.Factory(factory).createMediaSource(uri)
like image 39
Mladen Rakonjac Avatar answered Oct 21 '22 06:10

Mladen Rakonjac