feat: service-owned queue, full player, audio consistency and mood settings
CI / build (push) Successful in 2m40s
CI / play (push) Skipped

- Android Media3 service owns a real timeline: gapless playback, notification
  and headset next/back, 2 s previous rule, queue survives task swipes
- per-track loudness gain via an Android PCM processor and desktop mixer
- optional 0-8 s fade between tracks; full-screen player with quality info
- per-mood offline switch auto-syncs songs on Wi-Fi, three at a time
- dedicated mood settings screen with delete at the bottom
- one-tap add-to-mood in the player; sleep timer can finish the current track
- version 0.4.0
This commit is contained in:
TapTap committed 2026-11-19 16:38:21 +00:00
1 parent 8d7f6a0ccb
commit 1e3dac4e47
26 files changed
+2088 -689

No files matched your search

@@ -47,3 +47,5 @@ actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) {
actual fun decodeImage(bytes: ByteArray): ImageBitmap? =
runCatching { org.jetbrains.skia.Image.makeFromEncoded(bytes).toComposeImageBitmap() }.getOrNull()
actual fun isUnmeteredNetwork(): Boolean = true
@@ -1,10 +1,15 @@
package win.taptap.musicmanager.client
import kotlinx.browser.document
import kotlin.math.pow
import org.w3c.dom.HTMLAudioElement
import win.taptap.musicmanager.client.api.Song
import kotlinx.browser.document
import win.taptap.musicmanager.client.playback.AudioPlayer
import win.taptap.musicmanager.client.playback.PlaybackTrack
/**
* Browser playback. The queue lives here like on the other targets; the store
* advances at the end because HTMLAudioElement has one source at a time.
*/
class WebAudioPlayer : AudioPlayer {
private val audio: HTMLAudioElement =
@@ -12,17 +17,72 @@ class WebAudioPlayer : AudioPlayer {
preload = "auto"
}
override fun play(
source: String,
song: Song,
local: Boolean,
artworkUri: String?,
artworkBytes: ByteArray?,
) {
audio.src = source
private var tracks: List<PlaybackTrack> = emptyList()
private var index = 0
private var gain = 1.0
override fun setQueue(tracks: List<PlaybackTrack>, startIndex: Int, startAtSeconds: Double) {
if (tracks.isEmpty()) return
this.tracks = tracks
index = startIndex.coerceIn(tracks.indices)
playIndex(index, startAtSeconds)
}
override fun appendToQueue(tracks: List<PlaybackTrack>) {
this.tracks = this.tracks + tracks
}
override fun moveInQueue(fromIndex: Int, toIndex: Int) {
if (fromIndex !in tracks.indices || toIndex !in tracks.indices || fromIndex == toIndex) return
val moved = tracks.toMutableList()
val item = moved.removeAt(fromIndex)
moved.add(toIndex, item)
tracks = moved
if (index == fromIndex) {
index = toIndex
} else if (fromIndex < index && toIndex >= index) {
index -= 1
} else if (fromIndex > index && toIndex <= index) {
index += 1
}
}
override fun removeAt(index: Int) {
if (index !in tracks.indices) return
tracks = tracks.filterIndexed { i, _ -> i != index }
if (index < this.index) this.index = (this.index - 1).coerceAtLeast(0)
}
override fun playIndex(index: Int, startAtSeconds: Double) {
val track = tracks.getOrNull(index) ?: return
this.index = index
gain = track.gainDb?.let { 10.0.pow(it / 20.0) }?.coerceIn(0.0, 1.0) ?: 1.0
audio.volume = gain
audio.src = track.source
if (startAtSeconds > 0) audio.currentTime = startAtSeconds
audio.play()
}
override fun skipToNext() {
if (index + 1 < tracks.size) {
playIndex(index + 1)
} else {
audio.pause()
}
}
override fun skipToPrevious(restartAfterSeconds: Double) {
if (positionSeconds() > restartAfterSeconds || index == 0) {
seekTo(0.0)
} else {
playIndex(index - 1)
}
}
override fun currentIndex(): Int = index
override fun queueSize(): Int = tracks.size
override fun pause() {
audio.pause()
}
@@ -54,5 +114,6 @@ class WebAudioPlayer : AudioPlayer {
override fun release() {
stop()
tracks = emptyList()
}
}