ExoPlayer reading mp3 file from raw folder

偶尔善良 提交于 2019-12-06 00:32:13

It's possible to load files from the raw folder, the key is to use RawSourceDataSource.

Here's an example(in Kotlin) to create a LoopingMediaSource for an mp3file in the raw directory:

val uri = RawResourceDataSource.buildRawResourceUri(R.raw.mp3file)
val dataSource = RawResourceDataSource(this)
dataSource.open(DataSpec(uri))

val source = ExtractorMediaSource(uri, DataSource.Factory { dataSource }, Mp3Extractor.FACTORY, null, null)

LoopingMediaSource(source)

I couldn't load the mp3 files from the raw files so I ended up moving them to assets directory as per the discussion with one of the authors of ExoPlayer. (https://github.com/google/ExoPlayer/issues/556)

This is how I accessed the mp3 files from the assets if somebody will need it in the future:

mMediaPath = "asset:///my_ringtone.mp3";

and added this path the DemoPlayer as follows:

new DemoPlayer(new ExtractorRendererBuilder(this, userAgent, Uri.parse(mMediaPath), null, new Mp3Extractor()));

Thanks to all willing to answer my question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!