Search code examples
androidandroid-mediaplayerandroid-sdcardandroid-file

Simple mediaplayer play mp3 from file path?


I have a very simple mediaplayer that play background. It calls file from the apk, but I want it to play from any directory like as music or sdcard.

Here is my code:

private MediaPlayer mpintro;

.
.

mpintro = MediaPlayer.create(this, R.raw.intro);
        mpintro.setLooping(true);
        mpintro.start();

Solution

  • It works like this:

    mpintro = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/intro.mp3"));
    mpintro.setLooping(true);
            mpintro.start();
    

    It did not work properly as string filepath...