Broadcast song change even earlier
This commit is contained in:
parent
258972ad26
commit
601d9e70e1
@ -325,16 +325,36 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
|
|
||||||
mRandom = new Random();
|
mRandom = new Random();
|
||||||
|
|
||||||
boolean stateLoaded = loadState();
|
boolean stateLoaded = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
DataInputStream in = new DataInputStream(openFileInput(STATE_FILE));
|
||||||
|
if (in.readLong() == STATE_FILE_MAGIC) {
|
||||||
|
mCurrentSong = in.readInt();
|
||||||
|
int[] ids = new int[in.readInt()];
|
||||||
|
for (int i = ids.length; --i != -1; )
|
||||||
|
ids[i] = in.readInt();
|
||||||
|
mPendingSeek = in.readInt();
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
stateLoaded = true;
|
||||||
|
Song song = new Song(ids[mCurrentSong]);
|
||||||
|
broadcastSongChange(song);
|
||||||
|
|
||||||
|
mSongTimeline.ensureCapacity(ids.length);
|
||||||
|
for (int i = ids.length; --i != -1; )
|
||||||
|
mSongTimeline.add(i == mCurrentSong ? song : new Song(ids[i]));
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.w("VanillaMusic", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
retrieveSongs();
|
||||||
|
|
||||||
if (!stateLoaded)
|
if (!stateLoaded)
|
||||||
retrieveSongs();
|
|
||||||
|
|
||||||
broadcastSongChange(getSong(0));
|
broadcastSongChange(getSong(0));
|
||||||
|
|
||||||
// if we can, delay this so that the cover will show up faster in the activity
|
|
||||||
if (stateLoaded)
|
|
||||||
retrieveSongs();
|
|
||||||
|
|
||||||
mMediaPlayer = new MediaPlayer();
|
mMediaPlayer = new MediaPlayer();
|
||||||
mHandler = new MusicHandler();
|
mHandler = new MusicHandler();
|
||||||
|
|
||||||
@ -617,28 +637,6 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
private static final String STATE_FILE = "state";
|
private static final String STATE_FILE = "state";
|
||||||
private static final long STATE_FILE_MAGIC = 0x8a9d3f9fca31L;
|
private static final long STATE_FILE_MAGIC = 0x8a9d3f9fca31L;
|
||||||
|
|
||||||
private boolean loadState()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
DataInputStream in = new DataInputStream(openFileInput(STATE_FILE));
|
|
||||||
if (in.readLong() == STATE_FILE_MAGIC) {
|
|
||||||
mCurrentSong = in.readInt();
|
|
||||||
int n = in.readInt();
|
|
||||||
mSongTimeline.ensureCapacity(n);
|
|
||||||
while (--n != -1)
|
|
||||||
mSongTimeline.add(new Song(in.readInt()));
|
|
||||||
mPendingSeek = in.readInt();
|
|
||||||
in.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.w("VanillaMusic", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveState(boolean savePosition)
|
private void saveState(boolean savePosition)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user