// метод для получения сохраненной песни из SharedPreferences
public static String song_path(Context context) {
SharedPreferences sharedPreferences = act.getSharedPreferences("SHAREDpREFname", context.MODE_PRIVATE);
return sharedPreferences.getString("song_path", null);
}
// метод для сохранения предыдущей песни
public static void set_song_path(Context context, String path) {
SharedPreferences.Editor saver = act.getSharedPreferences("SHAREDpREFname", context.MODE_PRIVATE).edit();
saver.putString("song_path", path);
saver.commit();
}
private void initPlayer(final int position) {
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
mMediaPlayer.reset();
}
String sname = mySongs.get(position).getName().replace(".mp3", "").replace(".m4a", "").replace(".wav", "").replace(".m4b", "");
songTitle.setText(sname);
Uri songResourceUri = Uri.parse(mySongs.get(position).toString());
set_song_path(your_context,songResourceUri.toString());//this is to save
mMediaPlayer = MediaPlayer.create(getApplicationContext(), songResourceUri); // create and load mediaplayer with song resources
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
String totalTime = createTimeLabel(mMediaPlayer.getDuration());
totTime.setText(totalTime);
mSeekBar.setMax(mMediaPlayer.getDuration());
mMediaPlayer.start();
playIcon.setBackgroundResource(R.drawable.stop);
}
});
mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
int curSongPoition = position;
// code to repeat songs until the
if (curSongPoition < mySongs.size() - 1) {
curSongPoition++;
initPlayer(curSongPoition);
} else {
curSongPoition = 0;
initPlayer(curSongPoition);
}
}
});
}
Чтобы получить вызов пути к песне String path=song_path(your_context);
для Uri Uri savedsongResourceUri = Uri.parse(song_path(your_context));