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() {
|
public static void pauseSong() {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
musicService.pause();
|
musicService.pause();
|
||||||
|
|
@ -148,7 +142,7 @@ public class MusicPlayerRemote {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openQueue(final List<Song> queue, final int startPosition, final boolean startPlaying) {
|
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);
|
musicService.openQueue(queue, startPosition, startPlaying);
|
||||||
if (!PreferenceUtil.getInstance(musicService).getRememberShuffle()){
|
if (!PreferenceUtil.getInstance(musicService).getRememberShuffle()){
|
||||||
setShuffleMode(QueueManager.SHUFFLE_MODE_NONE);
|
setShuffleMode(QueueManager.SHUFFLE_MODE_NONE);
|
||||||
|
|
@ -162,19 +156,15 @@ public class MusicPlayerRemote {
|
||||||
startPosition = new Random().nextInt(queue.size());
|
startPosition = new Random().nextInt(queue.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
if (!tryToHandleOpenPlayingQueue(queue, startPosition) && musicService != null) {
|
||||||
openQueue(queue, startPosition, startPlaying);
|
openQueue(queue, startPosition, startPlaying);
|
||||||
setShuffleMode(QueueManager.SHUFFLE_MODE_SHUFFLE);
|
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 (getPlayingQueue() == queue) {
|
||||||
if (startPlaying) {
|
|
||||||
playSongAt(startPosition);
|
playSongAt(startPosition);
|
||||||
} else {
|
|
||||||
setPosition(startPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
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 RELEASE_WAKELOCK = 0;
|
||||||
public static final int PLAY_SONG = 3;
|
public static final int PLAY_SONG = 3;
|
||||||
public static final int PREPARE_NEXT = 4;
|
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 SAVE_QUEUE = 0;
|
||||||
public static final int LOAD_QUEUE = 9;
|
public static final int LOAD_QUEUE = 9;
|
||||||
|
|
@ -638,11 +637,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
position = 0;
|
position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startPlaying) {
|
|
||||||
playSongAt(position);
|
playSongAt(position);
|
||||||
} else {
|
|
||||||
setPosition(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyChange(QUEUE_CHANGED);
|
notifyChange(QUEUE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
@ -654,16 +649,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
playerHandler.obtainMessage(PLAY_SONG, position, 0).sendToTarget();
|
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() {
|
public void pause() {
|
||||||
if (playback.isPlaying()) {
|
if (playback.isPlaying()) {
|
||||||
playback.pause();
|
playback.pause();
|
||||||
|
|
@ -843,11 +828,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAY_SONG:
|
case PLAY_SONG:
|
||||||
service.playSongAtImpl(msg.arg1);
|
|
||||||
service.notifyChange(STATE_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SET_POSITION:
|
|
||||||
service.openTrackAndPrepareNextAt(msg.arg1);
|
service.openTrackAndPrepareNextAt(msg.arg1);
|
||||||
service.notifyChange(STATE_CHANGED);
|
service.notifyChange(STATE_CHANGED);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -215,9 +215,9 @@ public class QueueManager {
|
||||||
position = currentPosition - 1;
|
position = currentPosition - 1;
|
||||||
} else if (deletedPosition == currentPosition) {
|
} else if (deletedPosition == currentPosition) {
|
||||||
if (playingQueue.size() > deletedPosition) {
|
if (playingQueue.size() > deletedPosition) {
|
||||||
MusicPlayerRemote.setPosition(position);
|
MusicPlayerRemote.playSongAt(position);
|
||||||
} else {
|
} else {
|
||||||
MusicPlayerRemote.setPosition(position - 1);
|
MusicPlayerRemote.playSongAt(position - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue