playback: move most ops to player
This allows me to handle foreign MediaItem events easily. Not tested, don't have time.
This commit is contained in:
parent
05101c0e08
commit
5b8518a567
3 changed files with 360 additions and 243 deletions
|
@ -53,13 +53,8 @@ interface PlaybackStateHolder {
|
|||
|
||||
/**
|
||||
* Applies a completely new playback state to the holder.
|
||||
*
|
||||
* @param queue The new queue to use.
|
||||
* @param start The song to start playback from. Should be in the queue.
|
||||
* @param parent The parent to play from.
|
||||
* @param shuffled Whether the queue should be shuffled.
|
||||
*/
|
||||
fun newPlayback(queue: List<Song>, start: Song?, parent: MusicParent?, shuffled: Boolean)
|
||||
fun newPlayback(command: PlaybackCommand)
|
||||
|
||||
/**
|
||||
* Update the playing state of the audio player.
|
||||
|
|
|
@ -438,15 +438,11 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
|
|||
|
||||
@Synchronized
|
||||
override fun play(command: PlaybackCommand) {
|
||||
play(command.song, command.parent, command.queue, command.shuffled)
|
||||
}
|
||||
|
||||
private fun play(song: Song?, parent: MusicParent?, queue: List<Song>, shuffled: Boolean) {
|
||||
val stateHolder = stateHolder ?: return
|
||||
logD("Playing ${song} from $parent in ${queue.size}-song queue [shuffled=${shuffled}]")
|
||||
logD("Playing $command")
|
||||
// Played something, so we are initialized now
|
||||
isInitialized = true
|
||||
stateHolder.newPlayback(queue, song, parent, shuffled)
|
||||
stateHolder.newPlayback(command)
|
||||
}
|
||||
|
||||
// --- QUEUE FUNCTIONS ---
|
||||
|
@ -476,7 +472,7 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
|
|||
override fun playNext(songs: List<Song>) {
|
||||
if (currentSong == null) {
|
||||
logD("Nothing playing, short-circuiting to new playback")
|
||||
play(null, null, songs, false)
|
||||
play(QueueCommand(songs))
|
||||
} else {
|
||||
val stateHolder = stateHolder ?: return
|
||||
logD("Adding ${songs.size} songs to start of queue")
|
||||
|
@ -488,7 +484,7 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
|
|||
override fun addToQueue(songs: List<Song>) {
|
||||
if (currentSong == null) {
|
||||
logD("Nothing playing, short-circuiting to new playback")
|
||||
play(null, null, songs, false)
|
||||
play(QueueCommand(songs))
|
||||
} else {
|
||||
val stateHolder = stateHolder ?: return
|
||||
logD("Adding ${songs.size} songs to end of queue")
|
||||
|
@ -496,6 +492,12 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
|
|||
}
|
||||
}
|
||||
|
||||
private class QueueCommand(override val queue: List<Song>) : PlaybackCommand {
|
||||
override val song: Song? = null
|
||||
override val parent: MusicParent? = null
|
||||
override val shuffled = false
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun moveQueueItem(src: Int, dst: Int) {
|
||||
val stateHolder = stateHolder ?: return
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue