mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-16 19:50:35 +01:00
Semantically rename DownloadQueueSerializer to PlaybackStateSerializer
This commit is contained in:
parent
7d2923230c
commit
939cd8583c
@ -2,13 +2,13 @@ package org.moire.ultrasonic.di
|
|||||||
|
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.moire.ultrasonic.service.AudioFocusHandler
|
import org.moire.ultrasonic.service.AudioFocusHandler
|
||||||
import org.moire.ultrasonic.service.DownloadQueueSerializer
|
|
||||||
import org.moire.ultrasonic.service.Downloader
|
import org.moire.ultrasonic.service.Downloader
|
||||||
import org.moire.ultrasonic.service.ExternalStorageMonitor
|
import org.moire.ultrasonic.service.ExternalStorageMonitor
|
||||||
import org.moire.ultrasonic.service.JukeboxMediaPlayer
|
import org.moire.ultrasonic.service.JukeboxMediaPlayer
|
||||||
import org.moire.ultrasonic.service.LocalMediaPlayer
|
import org.moire.ultrasonic.service.LocalMediaPlayer
|
||||||
import org.moire.ultrasonic.service.MediaPlayerController
|
import org.moire.ultrasonic.service.MediaPlayerController
|
||||||
import org.moire.ultrasonic.service.MediaPlayerLifecycleSupport
|
import org.moire.ultrasonic.service.MediaPlayerLifecycleSupport
|
||||||
|
import org.moire.ultrasonic.service.PlaybackStateSerializer
|
||||||
import org.moire.ultrasonic.util.ShufflePlayBuffer
|
import org.moire.ultrasonic.util.ShufflePlayBuffer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,7 +17,7 @@ import org.moire.ultrasonic.util.ShufflePlayBuffer
|
|||||||
val mediaPlayerModule = module {
|
val mediaPlayerModule = module {
|
||||||
single { JukeboxMediaPlayer(get()) }
|
single { JukeboxMediaPlayer(get()) }
|
||||||
single { MediaPlayerLifecycleSupport() }
|
single { MediaPlayerLifecycleSupport() }
|
||||||
single { DownloadQueueSerializer() }
|
single { PlaybackStateSerializer() }
|
||||||
single { ExternalStorageMonitor() }
|
single { ExternalStorageMonitor() }
|
||||||
single { ShufflePlayBuffer() }
|
single { ShufflePlayBuffer() }
|
||||||
single { Downloader(get(), get(), get()) }
|
single { Downloader(get(), get(), get()) }
|
||||||
|
@ -32,7 +32,7 @@ import timber.log.Timber
|
|||||||
*/
|
*/
|
||||||
@Suppress("TooManyFunctions")
|
@Suppress("TooManyFunctions")
|
||||||
class MediaPlayerController(
|
class MediaPlayerController(
|
||||||
private val downloadQueueSerializer: DownloadQueueSerializer,
|
private val playbackStateSerializer: PlaybackStateSerializer,
|
||||||
private val externalStorageMonitor: ExternalStorageMonitor,
|
private val externalStorageMonitor: ExternalStorageMonitor,
|
||||||
private val downloader: Downloader,
|
private val downloader: Downloader,
|
||||||
private val shufflePlayBuffer: ShufflePlayBuffer,
|
private val shufflePlayBuffer: ShufflePlayBuffer,
|
||||||
@ -197,7 +197,7 @@ class MediaPlayerController(
|
|||||||
downloader.checkDownloads()
|
downloader.checkDownloads()
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex,
|
downloader.currentPlayingIndex,
|
||||||
playerPosition
|
playerPosition
|
||||||
@ -209,7 +209,7 @@ class MediaPlayerController(
|
|||||||
if (songs == null) return
|
if (songs == null) return
|
||||||
val filteredSongs = songs.filterNotNull()
|
val filteredSongs = songs.filterNotNull()
|
||||||
downloader.downloadBackground(filteredSongs, save)
|
downloader.downloadBackground(filteredSongs, save)
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex,
|
downloader.currentPlayingIndex,
|
||||||
playerPosition
|
playerPosition
|
||||||
@ -240,7 +240,7 @@ class MediaPlayerController(
|
|||||||
@Synchronized
|
@Synchronized
|
||||||
fun shuffle() {
|
fun shuffle() {
|
||||||
downloader.shuffle()
|
downloader.shuffle()
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex,
|
downloader.currentPlayingIndex,
|
||||||
playerPosition
|
playerPosition
|
||||||
@ -273,7 +273,7 @@ class MediaPlayerController(
|
|||||||
// If no MediaPlayerService is available, just empty the playlist
|
// If no MediaPlayerService is available, just empty the playlist
|
||||||
downloader.clearPlaylist()
|
downloader.clearPlaylist()
|
||||||
if (serialize) {
|
if (serialize) {
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex, playerPosition
|
downloader.currentPlayingIndex, playerPosition
|
||||||
)
|
)
|
||||||
@ -293,7 +293,7 @@ class MediaPlayerController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex,
|
downloader.currentPlayingIndex,
|
||||||
playerPosition
|
playerPosition
|
||||||
@ -310,7 +310,7 @@ class MediaPlayerController(
|
|||||||
}
|
}
|
||||||
downloader.removeFromPlaylist(downloadFile)
|
downloader.removeFromPlaylist(downloadFile)
|
||||||
|
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex,
|
downloader.currentPlayingIndex,
|
||||||
playerPosition
|
playerPosition
|
||||||
|
@ -32,7 +32,7 @@ import timber.log.Timber
|
|||||||
* @author Sindre Mehus
|
* @author Sindre Mehus
|
||||||
*/
|
*/
|
||||||
class MediaPlayerLifecycleSupport : KoinComponent {
|
class MediaPlayerLifecycleSupport : KoinComponent {
|
||||||
private val downloadQueueSerializer by inject<DownloadQueueSerializer>()
|
private val playbackStateSerializer by inject<PlaybackStateSerializer>()
|
||||||
private val mediaPlayerController by inject<MediaPlayerController>()
|
private val mediaPlayerController by inject<MediaPlayerController>()
|
||||||
private val downloader by inject<Downloader>()
|
private val downloader by inject<Downloader>()
|
||||||
private val mediaSessionEventDistributor by inject<MediaSessionEventDistributor>()
|
private val mediaSessionEventDistributor by inject<MediaSessionEventDistributor>()
|
||||||
@ -63,7 +63,7 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
|||||||
mediaPlayerController.onCreate()
|
mediaPlayerController.onCreate()
|
||||||
if (autoPlay) mediaPlayerController.preload()
|
if (autoPlay) mediaPlayerController.preload()
|
||||||
|
|
||||||
downloadQueueSerializer.deserializeDownloadQueue(object : Consumer<State?>() {
|
playbackStateSerializer.deserialize(object : Consumer<State?>() {
|
||||||
override fun accept(state: State?) {
|
override fun accept(state: State?) {
|
||||||
mediaPlayerController.restore(
|
mediaPlayerController.restore(
|
||||||
state!!.songs,
|
state!!.songs,
|
||||||
@ -75,7 +75,7 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
|||||||
|
|
||||||
// Work-around: Serialize again, as the restore() method creates a
|
// Work-around: Serialize again, as the restore() method creates a
|
||||||
// serialization without current playing info.
|
// serialization without current playing info.
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex,
|
downloader.currentPlayingIndex,
|
||||||
mediaPlayerController.playerPosition
|
mediaPlayerController.playerPosition
|
||||||
@ -93,7 +93,7 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
|||||||
|
|
||||||
if (!created) return
|
if (!created) return
|
||||||
|
|
||||||
downloadQueueSerializer.serializeDownloadQueueNow(
|
playbackStateSerializer.serializeNow(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex,
|
downloader.currentPlayingIndex,
|
||||||
mediaPlayerController.playerPosition
|
mediaPlayerController.playerPosition
|
||||||
|
@ -60,7 +60,7 @@ class MediaPlayerService : Service() {
|
|||||||
private val scrobbler = Scrobbler()
|
private val scrobbler = Scrobbler()
|
||||||
|
|
||||||
private val jukeboxMediaPlayer by inject<JukeboxMediaPlayer>()
|
private val jukeboxMediaPlayer by inject<JukeboxMediaPlayer>()
|
||||||
private val downloadQueueSerializer by inject<DownloadQueueSerializer>()
|
private val playbackStateSerializer by inject<PlaybackStateSerializer>()
|
||||||
private val shufflePlayBuffer by inject<ShufflePlayBuffer>()
|
private val shufflePlayBuffer by inject<ShufflePlayBuffer>()
|
||||||
private val downloader by inject<Downloader>()
|
private val downloader by inject<Downloader>()
|
||||||
private val localMediaPlayer by inject<LocalMediaPlayer>()
|
private val localMediaPlayer by inject<LocalMediaPlayer>()
|
||||||
@ -92,7 +92,7 @@ class MediaPlayerService : Service() {
|
|||||||
setupOnSongCompletedHandler()
|
setupOnSongCompletedHandler()
|
||||||
|
|
||||||
localMediaPlayer.onPrepared = {
|
localMediaPlayer.onPrepared = {
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex,
|
downloader.currentPlayingIndex,
|
||||||
playerPosition
|
playerPosition
|
||||||
@ -304,7 +304,7 @@ class MediaPlayerService : Service() {
|
|||||||
private fun resetPlayback() {
|
private fun resetPlayback() {
|
||||||
localMediaPlayer.reset()
|
localMediaPlayer.reset()
|
||||||
localMediaPlayer.setCurrentPlaying(null)
|
localMediaPlayer.setCurrentPlaying(null)
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex, playerPosition
|
downloader.currentPlayingIndex, playerPosition
|
||||||
)
|
)
|
||||||
@ -406,7 +406,7 @@ class MediaPlayerService : Service() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (playerState === PlayerState.PAUSED) {
|
if (playerState === PlayerState.PAUSED) {
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist, downloader.currentPlayingIndex, playerPosition
|
downloader.playlist, downloader.currentPlayingIndex, playerPosition
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -496,7 +496,7 @@ class MediaPlayerService : Service() {
|
|||||||
localMediaPlayer.setCurrentPlaying(null)
|
localMediaPlayer.setCurrentPlaying(null)
|
||||||
setNextPlaying()
|
setNextPlaying()
|
||||||
if (serialize) {
|
if (serialize) {
|
||||||
downloadQueueSerializer.serializeDownloadQueue(
|
playbackStateSerializer.serialize(
|
||||||
downloader.playlist,
|
downloader.playlist,
|
||||||
downloader.currentPlayingIndex, playerPosition
|
downloader.currentPlayingIndex, playerPosition
|
||||||
)
|
)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* DownloadQueueSerializer.kt
|
* PlaybackStateSerializer.kt
|
||||||
* Copyright (C) 2009-2021 Ultrasonic developers
|
* Copyright (C) 2009-2021 Ultrasonic developers
|
||||||
*
|
*
|
||||||
* Distributed under terms of the GNU GPLv3 license.
|
* Distributed under terms of the GNU GPLv3 license.
|
||||||
@ -24,10 +24,10 @@ import timber.log.Timber
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is responsible for the serialization / deserialization
|
* This class is responsible for the serialization / deserialization
|
||||||
* of the DownloadQueue (playlist) to the filesystem.
|
* of the playlist and the player state (e.g. current playing number and play position)
|
||||||
* It also serializes the player state e.g. current playing number and play position.
|
* to the filesystem.
|
||||||
*/
|
*/
|
||||||
class DownloadQueueSerializer : KoinComponent {
|
class PlaybackStateSerializer : KoinComponent {
|
||||||
|
|
||||||
private val context by inject<Context>()
|
private val context by inject<Context>()
|
||||||
private val mediaSessionHandler by inject<MediaSessionHandler>()
|
private val mediaSessionHandler by inject<MediaSessionHandler>()
|
||||||
@ -37,7 +37,7 @@ class DownloadQueueSerializer : KoinComponent {
|
|||||||
|
|
||||||
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
|
|
||||||
fun serializeDownloadQueue(
|
fun serialize(
|
||||||
songs: Iterable<DownloadFile>,
|
songs: Iterable<DownloadFile>,
|
||||||
currentPlayingIndex: Int,
|
currentPlayingIndex: Int,
|
||||||
currentPlayingPosition: Int
|
currentPlayingPosition: Int
|
||||||
@ -47,7 +47,7 @@ class DownloadQueueSerializer : KoinComponent {
|
|||||||
appScope.launch {
|
appScope.launch {
|
||||||
if (lock.tryLock()) {
|
if (lock.tryLock()) {
|
||||||
try {
|
try {
|
||||||
serializeDownloadQueueNow(songs, currentPlayingIndex, currentPlayingPosition)
|
serializeNow(songs, currentPlayingIndex, currentPlayingPosition)
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock()
|
lock.unlock()
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ class DownloadQueueSerializer : KoinComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun serializeDownloadQueueNow(
|
fun serializeNow(
|
||||||
songs: Iterable<DownloadFile>,
|
songs: Iterable<DownloadFile>,
|
||||||
currentPlayingIndex: Int,
|
currentPlayingIndex: Int,
|
||||||
currentPlayingPosition: Int
|
currentPlayingPosition: Int
|
||||||
@ -75,18 +75,18 @@ class DownloadQueueSerializer : KoinComponent {
|
|||||||
state.currentPlayingPosition
|
state.currentPlayingPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
FileUtil.serialize(context, state, Constants.FILENAME_DOWNLOADS_SER)
|
FileUtil.serialize(context, state, Constants.FILENAME_PLAYLIST_SER)
|
||||||
|
|
||||||
// This is called here because the queue is usually serialized after a change
|
// This is called here because the queue is usually serialized after a change
|
||||||
mediaSessionHandler.updateMediaSessionQueue(state.songs)
|
mediaSessionHandler.updateMediaSessionQueue(state.songs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deserializeDownloadQueue(afterDeserialized: Consumer<State?>) {
|
fun deserialize(afterDeserialized: Consumer<State?>) {
|
||||||
|
|
||||||
appScope.launch {
|
appScope.launch {
|
||||||
try {
|
try {
|
||||||
lock.lock()
|
lock.lock()
|
||||||
deserializeDownloadQueueNow(afterDeserialized)
|
deserializeNow(afterDeserialized)
|
||||||
setup.set(true)
|
setup.set(true)
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock()
|
lock.unlock()
|
||||||
@ -94,10 +94,10 @@ class DownloadQueueSerializer : KoinComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeDownloadQueueNow(afterDeserialized: Consumer<State?>) {
|
private fun deserializeNow(afterDeserialized: Consumer<State?>) {
|
||||||
|
|
||||||
val state = FileUtil.deserialize<State>(
|
val state = FileUtil.deserialize<State>(
|
||||||
context, Constants.FILENAME_DOWNLOADS_SER
|
context, Constants.FILENAME_PLAYLIST_SER
|
||||||
) ?: return
|
) ?: return
|
||||||
|
|
||||||
Timber.i(
|
Timber.i(
|
@ -118,7 +118,7 @@ object Constants {
|
|||||||
const val PREFERENCE_VALUE_ALL = 0
|
const val PREFERENCE_VALUE_ALL = 0
|
||||||
const val PREFERENCE_VALUE_A2DP = 1
|
const val PREFERENCE_VALUE_A2DP = 1
|
||||||
const val PREFERENCE_VALUE_DISABLED = 2
|
const val PREFERENCE_VALUE_DISABLED = 2
|
||||||
const val FILENAME_DOWNLOADS_SER = "downloadstate.ser"
|
const val FILENAME_PLAYLIST_SER = "downloadstate.ser"
|
||||||
const val ALBUM_ART_FILE = "folder.jpeg"
|
const val ALBUM_ART_FILE = "folder.jpeg"
|
||||||
const val STARRED = "starred"
|
const val STARRED = "starred"
|
||||||
const val ALPHABETICAL_BY_NAME = "alphabeticalByName"
|
const val ALPHABETICAL_BY_NAME = "alphabeticalByName"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user