Optimizing
This commit is contained in:
parent
50035ef8e6
commit
4b42ef6b9d
3 changed files with 74 additions and 24 deletions
|
|
@ -101,30 +101,51 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void playSongAt(final int position) {
|
||||
if (musicService != null) {
|
||||
musicService.playSongAt(position);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void setPosition(final int position) {
|
||||
if (musicService != null) {
|
||||
musicService.setPosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
public static void pauseSong() {
|
||||
if (musicService != null) {
|
||||
musicService.pause();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void playNextSong() {
|
||||
if (musicService != null) {
|
||||
musicService.playNextSong(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void playPreviousSong() {
|
||||
if (musicService != null) {
|
||||
musicService.playPreviousSong(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void back() {
|
||||
if (musicService != null) {
|
||||
musicService.back(true);
|
||||
|
|
@ -141,12 +162,42 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
}
|
||||
|
||||
public static void openQueue(final ArrayList<Song> playingQueue, final int startPosition, final boolean startPlaying) {
|
||||
if (musicService != null) {
|
||||
musicService.openAndPlayQueue(playingQueue, startPosition, startPlaying);
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void openQueue(final ArrayList<Song> queue, final int startPosition, final boolean startPlaying) {
|
||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
||||
musicService.openAndPlayQueue(queue, startPosition, startPlaying);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void openAndShuffleQueue(final ArrayList<Song> queue, boolean startPlaying) {
|
||||
int startPosition = 0;
|
||||
if (!queue.isEmpty()) {
|
||||
startPosition = new Random().nextInt(queue.size());
|
||||
}
|
||||
|
||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
||||
openQueue(queue, startPosition, startPlaying);
|
||||
setShuffleMode(MusicService.SHUFFLE_MODE_SHUFFLE);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean tryToHandleOpenPlayingQueue(final ArrayList<Song> queue, final int startPosition, final boolean startPlaying) {
|
||||
if (getPlayingQueue() == queue) {
|
||||
if (startPlaying) {
|
||||
playSongAt(startPosition);
|
||||
} else {
|
||||
setPosition(startPosition);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Song getCurrentSong() {
|
||||
if (musicService != null) {
|
||||
return musicService.getCurrentSong();
|
||||
|
|
@ -227,17 +278,6 @@ public class MusicPlayerRemote {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean openAndShuffleQueue(@NonNull final ArrayList<Song> songs, boolean startPlaying) {
|
||||
if (musicService != null) {
|
||||
if (!songs.isEmpty()) {
|
||||
MusicPlayerRemote.openQueue(songs, new Random().nextInt(songs.size()), startPlaying);
|
||||
setShuffleMode(MusicService.SHUFFLE_MODE_SHUFFLE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean playNext(Song song) {
|
||||
if (musicService != null) {
|
||||
musicService.addSong(getPosition() + 1, song);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue