feat: previous/scrub controls, mood mix and artwork for downloads
CI / build (push) Successful in 2m16s

Playback:
- Previous button: after two seconds it restarts the current track, otherwise
  it restores the last played track and puts the outgoing one back in front of
  the queue. History is persisted in the playback snapshot.
- The progress slider is draggable on every platform. Desktop previously
  refused to seek; it now restarts the decoder at the requested position,
  asking the server for a timeOffset on remote streams and skipping PCM frames
  for local files.

Artwork:
- Client downloads store the 320px cover next to the MP3 and Android sets it as
  MediaMetadata artwork data, so the notification and offline playback keep the
  cover. Deleting a download removes the image too.

Moods:
- New mood setting and editor slider choose the seed share of each radio batch;
  the server generates the rest from recommendations.

Library:
- Delta refresh now seeds its song map from both cached music and cached
  longform. Longform used to disappear after the first delta, which is why the
  artist list and artist playlists were empty while search still worked.
This commit is contained in:
TapTap committed 2026-11-15 17:07:11 +00:00
1 parent c0ff586686
commit 17bda94bfc
18 files changed
+390 -27

No files matched your search

@@ -244,6 +244,88 @@ class AppStoreTest {
store.release()
}
@Test
fun `previous restarts after two seconds and restores the last track before it`() = runTest {
val storage = MemoryStorage()
val cache = LibraryCache(storage)
cache.save(CachedState(serverUrl = "http://music", songs = listOf(song("a"), song("b"), song("c"))))
val player = FakePlayer()
val store = store(storage, cache, player)
runCurrent()
store.playAll(shuffled = false)
runCurrent()
store.skip()
runCurrent()
assertEquals("b", store.state.value.current?.id)
assertEquals(listOf("a"), store.state.value.history.map { it.id })
store.seekTo(5.0)
store.previous()
assertEquals("b", store.state.value.current?.id)
assertEquals(0.0, store.state.value.positionSeconds)
assertEquals(0.0, player.seeks.last())
store.previous()
runCurrent()
assertEquals("a", store.state.value.current?.id)
assertEquals(listOf("b", "c"), store.state.value.queue.map { it.id })
assertTrue(store.state.value.history.isEmpty())
assertEquals("a", player.played.last())
assertTrue(cache.loadPlayback()?.history?.isEmpty() == true)
store.release()
}
@Test
fun `delta refresh keeps cached longform songs`() = runTest {
val storage = MemoryStorage()
val cache = LibraryCache(storage)
cache.saveSession(
SessionState(
"http://music",
"token",
User("alice", admin = false, musicFolders = listOf(1), longformFolders = listOf(10)),
),
)
cache.save(
CachedState(
serverUrl = "http://music",
revision = "r1",
songs = listOf(song("m1")),
longform = listOf(song("l1", artist = "Die drei ???", folderId = 10)),
),
)
val engine = MockEngine { request ->
when (request.url.encodedPath) {
"/api/v1/moods" -> respond("""{"moods":[]}""", HttpStatusCode.OK, jsonHeaders)
"/api/v1/library/songs" -> respond(
"""{"songs":[],"revision":"r2"}""",
HttpStatusCode.OK,
jsonHeaders,
)
"/api/v1/longform/progress" -> respond(
"""{"items":[]}""",
HttpStatusCode.OK,
jsonHeaders,
)
else -> respondError(HttpStatusCode.NotFound)
}
}
val store = AppStore(
scope = this,
api = ApiClient(configuredHttpClient(engine)),
storage = storage,
player = FakePlayer(),
cache = cache,
)
runCurrent()
awaitState { cache.load()?.revision == "r2" }
assertEquals(listOf("m1"), store.state.value.library.map { it.id })
assertEquals(listOf("l1"), store.state.value.longform.map { it.id })
store.release()
}
@Test
fun `playing an artist queues only that longform artist`() = runTest {
val storage = MemoryStorage()
@@ -362,14 +444,23 @@ class AppStoreTest {
private class FakePlayer : AudioPlayer {
val played = mutableListOf<String>()
val seeks = mutableListOf<Double>()
var paused = false
private set
private var playing = false
private var position = 0.0
override fun play(source: String, song: Song, local: Boolean, artworkUri: String?) {
override fun play(
source: String,
song: Song,
local: Boolean,
artworkUri: String?,
artworkBytes: ByteArray?,
) {
played += song.id
playing = true
paused = false
position = 0.0
}
override fun pause() {
@@ -388,10 +479,13 @@ class AppStoreTest {
override fun isPlaying(): Boolean = playing
override fun isFinished(): Boolean = false
override fun positionSeconds(): Double = 0.0
override fun positionSeconds(): Double = position
override fun durationSeconds(): Double = 0.0
override val canSeek: Boolean = false
override fun seekTo(seconds: Double) = Unit
override val canSeek: Boolean = true
override fun seekTo(seconds: Double) {
position = seconds
seeks += seconds
}
override fun release() {
playing = false
}
@@ -5,6 +5,7 @@ import win.taptap.musicmanager.client.data.AppStorage
/** In-memory [AppStorage] for store and cache tests. */
internal class MemoryStorage : AppStorage {
private val files = mutableMapOf<String, String>()
private val artwork = mutableMapOf<String, ByteArray>()
override fun read(name: String): String? = files[name]
@@ -18,7 +19,14 @@ internal class MemoryStorage : AppStorage {
override fun saveDownload(songId: String, bytes: ByteArray): String? = null
override fun downloadPath(songId: String): String? = null
override fun saveArtwork(songId: String, bytes: ByteArray): String? {
artwork[songId] = bytes
return "memory://$songId.jpg"
}
override fun artworkBytes(songId: String): ByteArray? = artwork[songId]
override fun listDownloads(): Map<String, Long> = emptyMap()
override fun deleteDownload(songId: String) = Unit
override fun deleteDownload(songId: String) {
artwork.remove(songId)
}
override fun storageUsedBytes(): Long = 0
}