I have Implemented this code to play the Sound file available in res/drawable/testing123.mp3 file.
The code is :
public void playSound()
{
boolean mStartPlaying = true;
if (mStartPlaying==true)
{
// String word = wordValue.getText().toString();
String file = Environment.getExternalStorageDirectory().getAbsolutePath();
String sound = file+"/testing123.mp3";
//System.out.println("Before Allocation file is: "+file);
//rePlay.setText("Stop");
mPlayer = new MediaPlayer();
try
{
mPlayer.setDataSource(sound);
mPlayer.prepare();
mPlayer.start();
}
catch (IOException e)
{
Log.e(LOG_TAG, "prepare() failed");
}
}
else
{
// stopPlaying();
//rePlay.setText("Replay");
mPlayer.release();
mPlayer = null;
}
mStartPlaying = !mStartPlaying;
}
But i am not able to play it.
The Sound file is in the res/drawable/testing123.mp3
So Please help me, why i am not able to play that file ?
Thanks.
In my applications I put audio files in the /res/raw folder. For example I have an mp3 file used for notifications called “notify.mp3” in my raw folder and I can access it by
Uri uri = Uri.parse("android.resource://com.darrenmowat.boothr/" + R.raw.notify);You could then use
mPlayer.setDataSource(context, uri);to set the data source.