Don't crash with an invalid state

This commit is contained in:
Christopher Eby 2010-03-08 01:45:05 -06:00
parent f108489413
commit ed670a73e3

View File

@ -323,6 +323,8 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
mRandom = new Random();
boolean stateLoaded = true;
try {
DataInputStream in = new DataInputStream(openFileInput(STATE_FILE));
if (in.readLong() == STATE_FILE_MAGIC) {
@ -337,7 +339,10 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
in.close();
Song song = new Song(ids[mCurrentSong]);
broadcastSongChange(song);
if (song.path == null)
stateLoaded = false;
else
broadcastSongChange(song);
ArrayList<Song> timeline = new ArrayList<Song>(n);
for (int i = 0; i != n; ++i)
@ -351,7 +356,8 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
Log.w("VanillaMusic", e);
}
boolean stateLoaded = mSongTimeline != null;
if (stateLoaded)
stateLoaded = mSongTimeline != null;
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
@ -650,7 +656,14 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
mSongTimeline.add(randomSong());
}
return mSongTimeline.get(pos);
Song song = mSongTimeline.get(pos);
if (song.path == null) {
song = randomSong();
mSongTimeline.set(pos, song);
}
return song;
}
}