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.
59 lines
1.3 KiB
Kotlin
59 lines
1.3 KiB
Kotlin
package win.taptap.musicmanager.client
|
|
|
|
import kotlinx.browser.document
|
|
import org.w3c.dom.HTMLAudioElement
|
|
import win.taptap.musicmanager.client.api.Song
|
|
import win.taptap.musicmanager.client.playback.AudioPlayer
|
|
|
|
class WebAudioPlayer : AudioPlayer {
|
|
|
|
private val audio: HTMLAudioElement =
|
|
(document.createElement("audio") as HTMLAudioElement).apply {
|
|
preload = "auto"
|
|
}
|
|
|
|
override fun play(
|
|
source: String,
|
|
song: Song,
|
|
local: Boolean,
|
|
artworkUri: String?,
|
|
artworkBytes: ByteArray?,
|
|
) {
|
|
audio.src = source
|
|
audio.play()
|
|
}
|
|
|
|
override fun pause() {
|
|
audio.pause()
|
|
}
|
|
|
|
override fun resume() {
|
|
audio.play()
|
|
}
|
|
|
|
override fun stop() {
|
|
audio.pause()
|
|
audio.removeAttribute("src")
|
|
audio.load()
|
|
}
|
|
|
|
override fun isPlaying(): Boolean = !audio.paused && !audio.ended
|
|
|
|
override fun isFinished(): Boolean = audio.ended
|
|
|
|
override fun positionSeconds(): Double = audio.currentTime.takeIf { it.isFinite() } ?: 0.0
|
|
|
|
override fun durationSeconds(): Double =
|
|
audio.duration.takeIf { it.isFinite() && it > 0 } ?: 0.0
|
|
|
|
override val canSeek: Boolean = true
|
|
|
|
override fun seekTo(seconds: Double) {
|
|
audio.currentTime = seconds
|
|
}
|
|
|
|
override fun release() {
|
|
stop()
|
|
}
|
|
}
|