ExoPlayer reading mp3 file from raw folder

Is it possible to install the mp3 file located in the application source folder in ExoPlayer?

I tried to achieve this with the following piece of code with no success:

mMediaPath = "android.resource://" + getPackageName() + File.separator + R.raw.ringtone;

      

Any help is greatly appreciated!

+3


source to share


2 answers


It is possible to upload files from a raw folder, the key is to use RawSourceDataSource

.

Here is an example (in Kotlin) to create LoopingMediaSource

for an mp3file in the source 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)
+3


source


I couldn't download the mp3 files from the raw files, so I moved them to the resource directory as per discussion with one of the ExoPlayer authors. ( https://github.com/google/ExoPlayer/issues/556 )

This is how I got access to MP3 files from assets in case anyone needs it in the future:

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

      



and added this path to DemoPlayer like this:

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

      

Thanks to everyone who wants to answer my question.

+1


source







All Articles