Keep track of the timeline pos in CoverView
This way we don't cause funkiness when we store covers due to repeat that don't correspond to a timeline position
This commit is contained in:
parent
a13f7a7107
commit
49aaae4269
@ -60,6 +60,7 @@ public final class CoverView extends View {
|
||||
|
||||
private Song[] mSongs = new Song[3];
|
||||
private Bitmap[] mBitmaps = new Bitmap[3];
|
||||
private int mTimelinePos;
|
||||
private VelocityTracker mVelocityTracker;
|
||||
private float mLastMotionX;
|
||||
private float mStartX;
|
||||
@ -120,6 +121,11 @@ public final class CoverView extends View {
|
||||
public void setPlaybackService(IPlaybackService service)
|
||||
{
|
||||
mService = service;
|
||||
try {
|
||||
mTimelinePos = mService.getTimelinePos();
|
||||
} catch (RemoteException e) {
|
||||
mService = null;
|
||||
}
|
||||
refreshSongs();
|
||||
}
|
||||
|
||||
@ -399,6 +405,7 @@ public final class CoverView extends View {
|
||||
System.arraycopy(mBitmaps, from, mBitmaps, to, STORE_SIZE - 1);
|
||||
mSongs[i] = null;
|
||||
mBitmaps[i] = null;
|
||||
mTimelinePos += delta;
|
||||
reset();
|
||||
invalidate();
|
||||
|
||||
@ -491,7 +498,7 @@ public final class CoverView extends View {
|
||||
mLastMotionX = x;
|
||||
|
||||
if (deltaX < 0) {
|
||||
int availableToScroll = scrollX - (mBitmaps[0] == null ? width : 0);
|
||||
int availableToScroll = scrollX - (mBitmaps[0] == null || mTimelinePos == 0 ? width : 0);
|
||||
if (availableToScroll > 0)
|
||||
scrollBy(Math.max(-availableToScroll, deltaX), 0);
|
||||
} else if (deltaX > 0) {
|
||||
@ -508,7 +515,7 @@ public final class CoverView extends View {
|
||||
velocityTracker.computeCurrentVelocity(250);
|
||||
int velocity = (int) velocityTracker.getXVelocity();
|
||||
|
||||
int min = mBitmaps[0] == null ? 1 : 0;
|
||||
int min = mBitmaps[0] == null || mTimelinePos == 0 ? 1 : 0;
|
||||
int max = mBitmaps[2] == null ? 1 : 2;
|
||||
int nearestCover = (scrollX + width / 2) / width;
|
||||
int whichCover = Math.max(min, Math.min(nearestCover, max));
|
||||
@ -591,8 +598,9 @@ public final class CoverView extends View {
|
||||
} else if (PlaybackService.EVENT_CHANGED.equals(action)) {
|
||||
Song currentSong = mSongs[STORE_SIZE / 2];
|
||||
Song playingSong = intent.getParcelableExtra("song");
|
||||
mTimelinePos = intent.getIntExtra("pos", 0);
|
||||
if (currentSong == null || !currentSong.equals(playingSong))
|
||||
refreshSongs();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,9 @@ interface IPlaybackService {
|
||||
int getState();
|
||||
int getPosition();
|
||||
int getDuration();
|
||||
int getTimelinePos();
|
||||
|
||||
void setCurrentSong(int delta);
|
||||
void toggleFlag(int flag);
|
||||
void seekToProgress(int progress);
|
||||
}
|
||||
}
|
||||
|
@ -347,6 +347,7 @@ public class PlaybackService extends Service implements Handler.Callback, MediaP
|
||||
Intent intent = new Intent(EVENT_CHANGED);
|
||||
intent.putExtra("state", state);
|
||||
intent.putExtra("song", song);
|
||||
intent.putExtra("pos", mCurrentSong);
|
||||
sendBroadcast(intent);
|
||||
|
||||
if (mScrobble) {
|
||||
@ -870,6 +871,11 @@ public class PlaybackService extends Service implements Handler.Callback, MediaP
|
||||
}
|
||||
}
|
||||
|
||||
public int getTimelinePos()
|
||||
{
|
||||
return mCurrentSong;
|
||||
}
|
||||
|
||||
public void setCurrentSong(int delta)
|
||||
{
|
||||
PlaybackService.this.setCurrentSong(delta);
|
||||
@ -896,4 +902,4 @@ public class PlaybackService extends Service implements Handler.Callback, MediaP
|
||||
{
|
||||
return mBinder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user