javaandroidandroid-mediaplayerandroid-resourcesandroid-audiomanager

Audio File Path On Android Device


I have an mp3 file on my Galaxy S6 called song. I have a simple app with one Button that when clicked, I'd like my song file to play.

How can I get the path of that song and assign in to my MediaPlayer object?.


Solution

  • Here's a step by step short tutorial:

    If you want to access an external file:

    MediaPlayer mp = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/mySong.mp3")););
    mp.start();
    

    And ofc, don't forget the permissions:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>