Simple mediaplayer play mp3 from file path? Simple mediaplayer play mp3 from file path? android android

Simple mediaplayer play mp3 from file path?


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


String filePath = Environment.getExternalStorageDirectory()+"/yourfolderNAme/yopurfile.mp3";mediaPlayer = new  MediaPlayer();mediaPlayer.setDataSource(filePath);mediaPlayer.prepare();   mediaPlayer.start()

and this play from raw folder.

int resID = myContext.getResources().getIdentifier(playSoundName,"raw",myContext.getPackageName());            MediaPlayer mediaPlayer = MediaPlayer.create(myContext,resID);            mediaPlayer.prepare();            mediaPlayer.start();

mycontext=application.this. use.


Here is the code to set up a MediaPlayer to play off of the SD card:

String PATH_TO_FILE = "/sdcard/music.mp3";    mediaPlayer = new  MediaPlayer();mediaPlayer.setDataSource(PATH_TO_FILE);mediaPlayer.prepare();   mediaPlayer.start()

You can see the full example here. Let me know if you have any problems.