android – ExoPlayer HlsMediaSource() deprecated-ThrowExceptions

Exception or error:

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

How to solve:

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)

Leave a Reply

Your email address will not be published. Required fields are marked *