Is there any possibility to set an mp3 file that's located in the app's raw folder to ExoPlayer?
I tried to achieve it with the following code snippet without success unfortunately:
mMediaPath = "android.resource://" + getPackageName() + File.separator + R.raw.ringtone;
Any help is greatly appreciated!
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With