I get a path of music file from my listview using startActivityForResult and then set that string for MediaPlayer with MediaPlayer.setDataSource(STRING);
First time I play the song with button it plays all right, and if I click button while song is playing it will reset and play again.
if (mMediaPlayer.isPlaying()) {
mMediaPlayer.reset();
}
But if I tap on button playback is completed it will not play again.
startActivityForResult
Intent i = new Intent(MainActivity.this, Activityone.class);
startActivityForResult(i, 0);
mMediaPlayer.reset();
In Listview :
music_column_index = musiccursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
String filename = musiccursor.getString(music_column_index);
Intent person = new Intent();
Bundle backpack = new Bundle();
backpack.putString("arnswer", filename);
person.putExtras(backpack);
setResult(RESULT_OK, person);
finish();
onActivityResult :
if (resultCode == RESULT_OK){
if(requestCode == 0) {
// handling code of startActivityForResult of first button
Bundle basket = data.getExtras();
s = basket.getString("arnswer");
}
and Button to start MediaPlayer :
public void pbutton1(View view) {
try {
if (mMediaPlayer.isPlaying()) {
mMediaPlayer.reset();
}
mMediaPlayer.setDataSource(s); //using string here
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (Exception e) {
}
LogCat :