refactor: remove duplicate MusicServie#setPostion(int position)
This commit is contained in:
parent
2c2fbb09b2
commit
f351429049
3 changed files with 7 additions and 37 deletions
|
|
@ -103,12 +103,6 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
}
|
||||
|
||||
public static void setPosition(final int position) {
|
||||
if (musicService != null) {
|
||||
musicService.setPosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
public static void pauseSong() {
|
||||
if (musicService != null) {
|
||||
musicService.pause();
|
||||
|
|
@ -148,7 +142,7 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
|
||||
public static void openQueue(final List<Song> queue, final int startPosition, final boolean startPlaying) {
|
||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition) && musicService != null) {
|
||||
musicService.openQueue(queue, startPosition, startPlaying);
|
||||
if (!PreferenceUtil.getInstance(musicService).getRememberShuffle()){
|
||||
setShuffleMode(QueueManager.SHUFFLE_MODE_NONE);
|
||||
|
|
@ -162,19 +156,15 @@ public class MusicPlayerRemote {
|
|||
startPosition = new Random().nextInt(queue.size());
|
||||
}
|
||||
|
||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition) && musicService != null) {
|
||||
openQueue(queue, startPosition, startPlaying);
|
||||
setShuffleMode(QueueManager.SHUFFLE_MODE_SHUFFLE);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean tryToHandleOpenPlayingQueue(final List<Song> queue, final int startPosition, final boolean startPlaying) {
|
||||
private static boolean tryToHandleOpenPlayingQueue(final List<Song> queue, final int startPosition) {
|
||||
if (getPlayingQueue() == queue) {
|
||||
if (startPlaying) {
|
||||
playSongAt(startPosition);
|
||||
} else {
|
||||
setPosition(startPosition);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
public static final int RELEASE_WAKELOCK = 0;
|
||||
public static final int PLAY_SONG = 3;
|
||||
public static final int PREPARE_NEXT = 4;
|
||||
public static final int SET_POSITION = 5;
|
||||
|
||||
public static final int SAVE_QUEUE = 0;
|
||||
public static final int LOAD_QUEUE = 9;
|
||||
|
|
@ -638,11 +637,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
position = 0;
|
||||
}
|
||||
|
||||
if (startPlaying) {
|
||||
playSongAt(position);
|
||||
} else {
|
||||
setPosition(position);
|
||||
}
|
||||
|
||||
notifyChange(QUEUE_CHANGED);
|
||||
}
|
||||
|
|
@ -654,16 +649,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
playerHandler.obtainMessage(PLAY_SONG, position, 0).sendToTarget();
|
||||
}
|
||||
|
||||
public void setPosition(final int position) {
|
||||
// handle this on the handlers thread to avoid blocking the ui thread
|
||||
playerHandler.removeMessages(SET_POSITION);
|
||||
playerHandler.obtainMessage(SET_POSITION, position, 0).sendToTarget();
|
||||
}
|
||||
|
||||
private void playSongAtImpl(int position) {
|
||||
openTrackAndPrepareNextAt(position);
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
if (playback.isPlaying()) {
|
||||
playback.pause();
|
||||
|
|
@ -843,11 +828,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
break;
|
||||
|
||||
case PLAY_SONG:
|
||||
service.playSongAtImpl(msg.arg1);
|
||||
service.notifyChange(STATE_CHANGED);
|
||||
break;
|
||||
|
||||
case SET_POSITION:
|
||||
service.openTrackAndPrepareNextAt(msg.arg1);
|
||||
service.notifyChange(STATE_CHANGED);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -215,9 +215,9 @@ public class QueueManager {
|
|||
position = currentPosition - 1;
|
||||
} else if (deletedPosition == currentPosition) {
|
||||
if (playingQueue.size() > deletedPosition) {
|
||||
MusicPlayerRemote.setPosition(position);
|
||||
MusicPlayerRemote.playSongAt(position);
|
||||
} else {
|
||||
MusicPlayerRemote.setPosition(position - 1);
|
||||
MusicPlayerRemote.playSongAt(position - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue