Search code examples
androidexoplayer

ExoPlayer reading mp3 file from raw folder


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!


Solution

  • 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.