Don't crash with an invalid state
This commit is contained in:
parent
f108489413
commit
ed670a73e3
@ -323,6 +323,8 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
|
|
||||||
mRandom = new Random();
|
mRandom = new Random();
|
||||||
|
|
||||||
|
boolean stateLoaded = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DataInputStream in = new DataInputStream(openFileInput(STATE_FILE));
|
DataInputStream in = new DataInputStream(openFileInput(STATE_FILE));
|
||||||
if (in.readLong() == STATE_FILE_MAGIC) {
|
if (in.readLong() == STATE_FILE_MAGIC) {
|
||||||
@ -337,6 +339,9 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
Song song = new Song(ids[mCurrentSong]);
|
Song song = new Song(ids[mCurrentSong]);
|
||||||
|
if (song.path == null)
|
||||||
|
stateLoaded = false;
|
||||||
|
else
|
||||||
broadcastSongChange(song);
|
broadcastSongChange(song);
|
||||||
|
|
||||||
ArrayList<Song> timeline = new ArrayList<Song>(n);
|
ArrayList<Song> timeline = new ArrayList<Song>(n);
|
||||||
@ -351,7 +356,8 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
Log.w("VanillaMusic", e);
|
Log.w("VanillaMusic", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean stateLoaded = mSongTimeline != null;
|
if (stateLoaded)
|
||||||
|
stateLoaded = mSongTimeline != null;
|
||||||
|
|
||||||
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
@ -650,7 +656,14 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
mSongTimeline.add(randomSong());
|
mSongTimeline.add(randomSong());
|
||||||
}
|
}
|
||||||
|
|
||||||
return mSongTimeline.get(pos);
|
Song song = mSongTimeline.get(pos);
|
||||||
|
|
||||||
|
if (song.path == null) {
|
||||||
|
song = randomSong();
|
||||||
|
mSongTimeline.set(pos, song);
|
||||||
|
}
|
||||||
|
|
||||||
|
return song;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user