Save repeat and shuffle states

This commit is contained in:
Christopher Eby 2010-04-12 21:35:58 -05:00
parent 23cadc916e
commit 0776b1e08b
2 changed files with 12 additions and 5 deletions

View File

@ -127,6 +127,8 @@ public final class PlaybackService extends Service implements Handler.Callback,
mSongTimeline = new ArrayList<Song>(state.savedIds.length);
mTimelinePos = state.savedIndex;
mPendingSeek = state.savedSeek;
mState |= state.savedState;
mRepeatStart = state.repeatStart;
for (int i = 0; i != state.savedIds.length; ++i)
mSongTimeline.add(new Song(state.savedIds[i], state.savedFlags[i]));
@ -636,7 +638,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
private void saveState(boolean savePosition)
{
PlaybackServiceState.saveState(this, mSongTimeline, mTimelinePos, savePosition && mMediaPlayer != null ? mMediaPlayer.getCurrentPosition() : 0);
PlaybackServiceState.saveState(this, mSongTimeline, mTimelinePos, savePosition && mMediaPlayer != null ? mMediaPlayer.getCurrentPosition() : 0, mState & (FLAG_REPEAT + FLAG_SHUFFLE), mRepeatStart);
}
private void go(int delta, boolean doubleLaunchesActivity, boolean autoPlay)

View File

@ -29,12 +29,14 @@ import android.util.Log;
public class PlaybackServiceState {
private static final String STATE_FILE = "state";
private static final long STATE_FILE_MAGIC = 0x8a9d3f2fca31L;
private static final long STATE_FILE_MAGIC = 0x8a9d3f2fca32L;
public int savedIndex;
public long[] savedIds;
public int[] savedFlags;
public int savedSeek;
public int savedState;
public int repeatStart;
public boolean load(Context context)
{
@ -52,11 +54,12 @@ public class PlaybackServiceState {
savedFlags[i] = in.readInt();
}
savedSeek = in.readInt();
return true;
savedState = in.readInt();
repeatStart = in.readInt();
}
in.close();
return n > 0;
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
@ -66,7 +69,7 @@ public class PlaybackServiceState {
return false;
}
public static void saveState(Context context, List<Song> songs, int index, int seek)
public static void saveState(Context context, List<Song> songs, int index, int seek, int state, int repeatStart)
{
try {
DataOutputStream out = new DataOutputStream(context.openFileOutput(STATE_FILE, 0));
@ -80,6 +83,8 @@ public class PlaybackServiceState {
out.writeInt(song.flags);
}
out.writeInt(seek);
out.writeInt(state);
out.writeInt(repeatStart);
out.close();
} catch (IOException e) {
Log.w("VanillaMusic", e);