通知栏三按钮、播放页/迷你播放条/当前队列 UI、播放模式与 FFmpeg/Media3 兜底逻辑
This commit is contained in:
parent
beaf2859bc
commit
1f34785bde
@ -67,6 +67,7 @@ dependencies {
|
||||
implementation(libs.ffmpeg.kit.min)
|
||||
implementation(libs.androidx.media3.exoplayer)
|
||||
implementation(libs.timber)
|
||||
implementation(libs.coil.compose)
|
||||
ksp(libs.androidx.room.compiler)
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(platform(libs.androidx.compose.bom))
|
||||
|
||||
@ -29,6 +29,7 @@ import com.audio.vibe.ui.i18n.LocalSelectedLanguage
|
||||
import com.audio.vibe.ui.i18n.resolveLanguage
|
||||
import com.audio.vibe.ui.i18n.stringsFor
|
||||
import com.audio.vibe.ui.musicmanager.MusicManagerScreen
|
||||
import com.audio.vibe.ui.player.PlayerScreen
|
||||
import com.audio.vibe.ui.premium.PremiumScreen
|
||||
import com.audio.vibe.ui.settings.SettingsScreen
|
||||
import com.audio.vibe.ui.theme.AudioVibeTheme
|
||||
@ -114,9 +115,13 @@ fun AppNavHost(
|
||||
composable("music") {
|
||||
MusicManagerScreen(
|
||||
onBack = { navController.popBackStack() },
|
||||
toEditor = { navController.navigate("editor") }
|
||||
toEditor = { navController.navigate("editor") },
|
||||
toPlayer = { navController.navigate("player") }
|
||||
)
|
||||
}
|
||||
composable("player") {
|
||||
PlayerScreen(onBack = { navController.popBackStack() })
|
||||
}
|
||||
composable("settings") {
|
||||
SettingsScreen(
|
||||
onBack = { navController.popBackStack() },
|
||||
|
||||
@ -10,12 +10,14 @@ import android.os.Build
|
||||
import android.os.ParcelFileDescriptor
|
||||
import android.os.SystemClock
|
||||
import android.provider.DocumentsContract
|
||||
import androidx.annotation.OptIn
|
||||
import androidx.media3.common.AudioAttributes
|
||||
import androidx.media3.common.C
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.MediaMetadata
|
||||
import androidx.media3.common.PlaybackException
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.exoplayer.DefaultRenderersFactory
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import com.arthenica.ffmpegkit.FFmpegKit
|
||||
@ -23,6 +25,7 @@ import com.arthenica.ffmpegkit.FFmpegKitConfig
|
||||
import com.arthenica.ffmpegkit.FFmpegSession
|
||||
import com.arthenica.ffmpegkit.Level
|
||||
import com.arthenica.ffmpegkit.LogCallback
|
||||
import com.audio.vibe.domain.model.PlayMode
|
||||
import com.audio.vibe.domain.model.PlaybackTrack
|
||||
import com.audio.vibe.domain.model.ScannedAudioTrack
|
||||
import java.io.Closeable
|
||||
@ -43,6 +46,7 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
|
||||
@OptIn(UnstableApi::class)
|
||||
class AudioPlaybackController(context: Context) {
|
||||
private val appContext = context.applicationContext
|
||||
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
||||
@ -59,8 +63,14 @@ class AudioPlaybackController(context: Context) {
|
||||
private var trackResolver: (suspend (Long) -> PlaybackTrack?)? = null
|
||||
private var playbackGeneration: Long = 0L
|
||||
private var progressJob: Job? = null
|
||||
private var queueSnapshotJob: Job? = null
|
||||
private var ffmpegPositionMs: Long = 0L
|
||||
private var activeOutputParameters: PlaybackAudioParameters? = null
|
||||
private var queueItems: List<PlaybackQueueItem> = emptyList()
|
||||
private var playMode: PlayMode = PlayMode.default
|
||||
private var shuffleIndices: IntArray = IntArray(0)
|
||||
private var shufflePosition: Int = -1
|
||||
private var transitionIsPlayingOverride: Boolean? = null
|
||||
|
||||
init {
|
||||
val audioAttributes = AudioAttributes.Builder()
|
||||
@ -83,8 +93,7 @@ class AudioPlaybackController(context: Context) {
|
||||
currentTrack?.id?.toString() ?: "unknown",
|
||||
currentTrack?.title ?: "unknown"
|
||||
)
|
||||
publishState()
|
||||
if (isInvalidMedia3Duration(player.duration)) {
|
||||
if (shouldFallbackForInvalidMedia3Duration(playbackState, player.duration)) {
|
||||
onPlayerError(
|
||||
PlaybackException(
|
||||
"Media3 invalid duration: ${player.duration}",
|
||||
@ -95,12 +104,21 @@ class AudioPlaybackController(context: Context) {
|
||||
return
|
||||
}
|
||||
if (playbackState == Player.STATE_ENDED) {
|
||||
playNext()
|
||||
moveToNext(manual = false)
|
||||
return
|
||||
}
|
||||
publishState(
|
||||
backendOverride = if (playbackState == Player.STATE_READY) {
|
||||
PlaybackBackend.Media3
|
||||
} else {
|
||||
null
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
||||
if (activeBackend == PlaybackBackend.Media3) {
|
||||
if (player.playbackState == Player.STATE_ENDED) return
|
||||
Timber.i(
|
||||
"Media3 isPlaying changed: isPlaying=%s positionMs=%d durationMs=%d trackId=%s",
|
||||
isPlaying,
|
||||
@ -108,7 +126,13 @@ class AudioPlaybackController(context: Context) {
|
||||
player.duration,
|
||||
currentTrack?.id?.toString() ?: "unknown"
|
||||
)
|
||||
publishState()
|
||||
publishState(
|
||||
backendOverride = if (player.playbackState == Player.STATE_READY) {
|
||||
PlaybackBackend.Media3
|
||||
} else {
|
||||
null
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,14 +176,20 @@ class AudioPlaybackController(context: Context) {
|
||||
startTrackId: Long,
|
||||
trackResolver: suspend (Long) -> PlaybackTrack?
|
||||
) {
|
||||
if (queueIds.isEmpty()) return
|
||||
if (queueIds.isEmpty()) {
|
||||
stop()
|
||||
return
|
||||
}
|
||||
val generation = nextPlaybackGeneration()
|
||||
stopActivePlayback()
|
||||
this.queueIds = queueIds
|
||||
this.trackResolver = trackResolver
|
||||
queueItems = queueIds.map { id -> PlaybackQueueItem(id = id) }
|
||||
currentIndex = queueIds.indexOf(startTrackId)
|
||||
.takeIf { it >= 0 }
|
||||
?: 0
|
||||
if (playMode == PlayMode.Shuffle) {
|
||||
buildShuffleIndices()
|
||||
}
|
||||
Timber.i(
|
||||
"Playback queue requested: generation=%d queueSize=%d startTrackId=%d resolvedStartIndex=%d",
|
||||
generation,
|
||||
@ -167,6 +197,7 @@ class AudioPlaybackController(context: Context) {
|
||||
startTrackId,
|
||||
currentIndex
|
||||
)
|
||||
loadQueueSnapshot(generation)
|
||||
scope.launch {
|
||||
playCurrent(generation)
|
||||
}
|
||||
@ -191,12 +222,19 @@ class AudioPlaybackController(context: Context) {
|
||||
true
|
||||
}
|
||||
|
||||
null -> false
|
||||
null -> {
|
||||
if (currentTrack == null || currentIndex !in queueIds.indices) return false
|
||||
val generation = nextPlaybackGeneration()
|
||||
scope.launch {
|
||||
playCurrent(generation)
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun playNext() {
|
||||
moveToNext()
|
||||
moveToNext(manual = true)
|
||||
}
|
||||
|
||||
fun playPrevious() {
|
||||
@ -205,29 +243,116 @@ class AudioPlaybackController(context: Context) {
|
||||
return
|
||||
}
|
||||
val generation = nextPlaybackGeneration()
|
||||
currentIndex = (currentIndex - 1).coerceAtLeast(0)
|
||||
currentIndex = when (playMode) {
|
||||
PlayMode.Shuffle -> previousShuffleIndex()
|
||||
else -> {
|
||||
if (currentIndex <= 0) queueIds.lastIndex else currentIndex - 1
|
||||
}
|
||||
}
|
||||
scope.launch {
|
||||
playCurrent(generation)
|
||||
}
|
||||
}
|
||||
|
||||
fun seekTo(positionMs: Long): Boolean {
|
||||
if (activeBackend != PlaybackBackend.Media3) return false
|
||||
val target = positionMs.coerceAtLeast(0L)
|
||||
player.seekTo(target)
|
||||
publishState()
|
||||
fun playQueueIndex(index: Int): Boolean {
|
||||
val playbackIndex = displayQueueIndices().getOrNull(index) ?: return false
|
||||
val generation = nextPlaybackGeneration()
|
||||
currentIndex = playbackIndex
|
||||
if (playMode == PlayMode.Shuffle) {
|
||||
ensureShuffleOrder()
|
||||
shufflePosition = shuffleIndices.indexOf(playbackIndex).takeIf { it >= 0 } ?: shufflePosition
|
||||
}
|
||||
scope.launch {
|
||||
playCurrent(generation)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun seekTo(positionMs: Long): Boolean {
|
||||
return when (activeBackend) {
|
||||
PlaybackBackend.Media3 -> {
|
||||
val target = boundedSeekPosition(positionMs)
|
||||
player.seekTo(target)
|
||||
publishState(positionOverrideMs = target)
|
||||
true
|
||||
}
|
||||
|
||||
PlaybackBackend.FfmpegAudioTrack -> {
|
||||
val track = currentTrack ?: return false
|
||||
val boundedTarget = boundedSeekPosition(positionMs, track.durationMs)
|
||||
val generation = nextPlaybackGeneration()
|
||||
ffmpegPositionMs = boundedTarget
|
||||
publishState(
|
||||
isPlayingOverride = true,
|
||||
backendOverride = PlaybackBackend.FfmpegAudioTrack,
|
||||
positionOverrideMs = boundedTarget
|
||||
)
|
||||
scope.launch {
|
||||
playWithFfmpeg(
|
||||
track = track,
|
||||
previousError = null,
|
||||
generation = generation,
|
||||
startPositionMs = boundedTarget
|
||||
)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
null -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun boundedSeekPosition(positionMs: Long, fallbackDurationMs: Long? = null): Long {
|
||||
val target = positionMs.coerceAtLeast(0L)
|
||||
val duration = when (activeBackend) {
|
||||
PlaybackBackend.Media3 -> player.duration
|
||||
.takeIf { it != C.TIME_UNSET && it > 0L }
|
||||
?: fallbackDurationMs?.takeIf { it > 0L }
|
||||
?: currentTrack?.durationMs?.takeIf { it > 0L }
|
||||
PlaybackBackend.FfmpegAudioTrack -> fallbackDurationMs?.takeIf { it > 0L }
|
||||
?: currentTrack?.durationMs?.takeIf { it > 0L }
|
||||
null -> fallbackDurationMs?.takeIf { it > 0L }
|
||||
}
|
||||
return duration?.let { target.coerceAtMost(it) } ?: target
|
||||
}
|
||||
|
||||
fun setPlayMode(mode: PlayMode) {
|
||||
if (mode == PlayMode.Shuffle) {
|
||||
buildShuffleIndices()
|
||||
}
|
||||
playMode = mode
|
||||
Timber.i("PlayMode changed: %s", mode.name)
|
||||
publishState()
|
||||
}
|
||||
|
||||
/** Build shuffled index array based on current queue. Current playing track goes first. */
|
||||
private fun buildShuffleIndices() {
|
||||
if (queueIds.isEmpty()) {
|
||||
shuffleIndices = IntArray(0)
|
||||
shufflePosition = -1
|
||||
return
|
||||
}
|
||||
val indices = (0 until queueIds.size).toMutableList()
|
||||
val current = indices.removeAt(currentIndex.coerceIn(0, indices.lastIndex))
|
||||
indices.shuffle()
|
||||
shuffleIndices = (listOf(current) + indices).toIntArray()
|
||||
shufflePosition = 0
|
||||
Timber.i("Shuffle indices built: current=%d order=%s", current, shuffleIndices.joinToString())
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
nextPlaybackGeneration()
|
||||
stopActivePlayback()
|
||||
queueIds = LongArray(0)
|
||||
queueItems = emptyList()
|
||||
queueSnapshotJob?.cancel()
|
||||
queueSnapshotJob = null
|
||||
currentIndex = -1
|
||||
currentTrack = null
|
||||
trackResolver = null
|
||||
ffmpegPositionMs = 0L
|
||||
activeOutputParameters = null
|
||||
transitionIsPlayingOverride = null
|
||||
_state.value = PlaybackState()
|
||||
}
|
||||
|
||||
@ -238,16 +363,19 @@ class AudioPlaybackController(context: Context) {
|
||||
player.release()
|
||||
}
|
||||
|
||||
private suspend fun playCurrent(generation: Long) {
|
||||
private suspend fun playCurrent(generation: Long, resolveFailureCount: Int = 0) {
|
||||
val track = loadCurrentTrack(generation) ?: run {
|
||||
Timber.w(
|
||||
"Playback track resolve failed: generation=%d currentGeneration=%d index=%d queueSize=%d",
|
||||
"Playback track resolve failed: generation=%d currentGeneration=%d index=%d queueSize=%d resolveFailureCount=%d",
|
||||
generation,
|
||||
playbackGeneration,
|
||||
currentIndex,
|
||||
queueIds.size
|
||||
queueIds.size,
|
||||
resolveFailureCount
|
||||
)
|
||||
if (generation == playbackGeneration) moveToNext()
|
||||
if (generation == playbackGeneration) {
|
||||
handleTrackResolveFailure(resolveFailureCount)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (generation != playbackGeneration) return
|
||||
@ -278,6 +406,14 @@ class AudioPlaybackController(context: Context) {
|
||||
)
|
||||
return
|
||||
}
|
||||
val previousIsPlaying = _state.value.isPlaying
|
||||
transitionIsPlayingOverride = previousIsPlaying
|
||||
publishState(
|
||||
isPlayingOverride = previousIsPlaying,
|
||||
backendOverride = null,
|
||||
positionOverrideMs = 0L
|
||||
)
|
||||
stopActivePlaybackForTrackSwitch()
|
||||
if (track.requiresFfmpegPlayback()) {
|
||||
playWithFfmpeg(track, previousError = null, generation)
|
||||
} else {
|
||||
@ -305,24 +441,29 @@ class AudioPlaybackController(context: Context) {
|
||||
player.setMediaItem(track.toMediaItem())
|
||||
player.prepare()
|
||||
player.play()
|
||||
publishState(isPlayingOverride = true, backendOverride = PlaybackBackend.Media3)
|
||||
publishState(backendOverride = null)
|
||||
startProgressUpdates(generation)
|
||||
}
|
||||
|
||||
private fun playWithFfmpeg(track: PlaybackTrack?, previousError: String?, generation: Long) {
|
||||
private fun playWithFfmpeg(
|
||||
track: PlaybackTrack?,
|
||||
previousError: String?,
|
||||
generation: Long,
|
||||
startPositionMs: Long = 0L
|
||||
) {
|
||||
if (track == null) return
|
||||
if (generation != playbackGeneration) return
|
||||
progressJob?.cancel()
|
||||
progressJob = null
|
||||
player.stop()
|
||||
ffmpegPositionMs = 0L
|
||||
ffmpegPositionMs = startPositionMs.coerceAtLeast(0L)
|
||||
activeOutputParameters = null
|
||||
activeBackend = PlaybackBackend.FfmpegAudioTrack
|
||||
previousError?.let { message ->
|
||||
Timber.w("Media3 playback failed, falling back to FFmpeg PCM: %s", message)
|
||||
}
|
||||
Timber.i(
|
||||
"FFmpeg playback start: generation=%d id=%d title=%s format=%s uri=%s durationMs=%s sourceSampleRate=%s sourceBitDepth=%s reason=%s",
|
||||
"FFmpeg playback start: generation=%d id=%d title=%s format=%s uri=%s durationMs=%s sourceSampleRate=%s sourceBitDepth=%s startPositionMs=%d reason=%s",
|
||||
generation,
|
||||
track.id,
|
||||
track.title,
|
||||
@ -331,6 +472,7 @@ class AudioPlaybackController(context: Context) {
|
||||
track.durationMs?.toString() ?: "unknown",
|
||||
track.sampleRateHz?.toString() ?: "unknown",
|
||||
track.bitDepth ?: "unknown",
|
||||
startPositionMs,
|
||||
track.ffmpegDecisionReason()
|
||||
)
|
||||
publishState(
|
||||
@ -339,6 +481,7 @@ class AudioPlaybackController(context: Context) {
|
||||
)
|
||||
ffmpegRenderer.play(
|
||||
track = track,
|
||||
startPositionMs = startPositionMs,
|
||||
onOutputReady = { outputParameters ->
|
||||
Timber.i(
|
||||
"FFmpeg output ready: trackId=%d sampleRate=%s bitDepth=%s channels=%s encoding=%s chain=%s",
|
||||
@ -359,7 +502,7 @@ class AudioPlaybackController(context: Context) {
|
||||
onProgress = { positionMs ->
|
||||
scope.launch {
|
||||
if (generation == playbackGeneration) {
|
||||
ffmpegPositionMs = positionMs
|
||||
ffmpegPositionMs = startPositionMs + positionMs
|
||||
publishState()
|
||||
}
|
||||
}
|
||||
@ -377,7 +520,7 @@ class AudioPlaybackController(context: Context) {
|
||||
generation == playbackGeneration &&
|
||||
activeBackend == PlaybackBackend.FfmpegAudioTrack
|
||||
) {
|
||||
moveToNext()
|
||||
moveToNext(manual = false)
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -398,27 +541,181 @@ class AudioPlaybackController(context: Context) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun moveToNext() {
|
||||
private fun handleTrackResolveFailure(resolveFailureCount: Int) {
|
||||
if (playMode == PlayMode.RepeatOne) {
|
||||
pauseAtCurrentItem()
|
||||
return
|
||||
}
|
||||
|
||||
val nextFailureCount = resolveFailureCount + 1
|
||||
if (nextFailureCount >= queueIds.size) {
|
||||
Timber.w(
|
||||
"Playback resolve failed for every queue item: failureCount=%d queueSize=%d; stopping",
|
||||
nextFailureCount,
|
||||
queueIds.size
|
||||
)
|
||||
stop()
|
||||
return
|
||||
}
|
||||
|
||||
if (playMode == PlayMode.ListOnce && currentIndex >= queueIds.lastIndex) {
|
||||
Timber.w(
|
||||
"Playback ListOnce resolve failed at queue end: index=%d queueSize=%d; stopping",
|
||||
currentIndex,
|
||||
queueIds.size
|
||||
)
|
||||
stop()
|
||||
return
|
||||
}
|
||||
|
||||
moveToNext(manual = false, resolveFailureCount = nextFailureCount)
|
||||
}
|
||||
|
||||
private fun moveToNext(manual: Boolean, resolveFailureCount: Int = 0) {
|
||||
if (queueIds.isEmpty()) {
|
||||
Timber.i("Playback moveToNext requested with empty queue; stopping")
|
||||
stop()
|
||||
return
|
||||
}
|
||||
val generation = nextPlaybackGeneration()
|
||||
currentIndex += 1
|
||||
if (!manual && playMode == PlayMode.ListOnce && currentIndex >= queueIds.lastIndex) {
|
||||
Timber.i(
|
||||
"Playback moveToNext: generation=%d nextIndex=%d queueSize=%d",
|
||||
generation,
|
||||
"Playback ListOnce reached queue end: index=%d queueSize=%d",
|
||||
currentIndex,
|
||||
queueIds.size
|
||||
)
|
||||
if (currentIndex >= queueIds.size) {
|
||||
stop()
|
||||
pauseAtCurrentItem()
|
||||
return
|
||||
}
|
||||
val generation = nextPlaybackGeneration()
|
||||
when (playMode) {
|
||||
PlayMode.RepeatOne -> {
|
||||
if (!manual) {
|
||||
Timber.i("Playback RepeatOne: replaying index=%d", currentIndex)
|
||||
scope.launch { playCurrent(generation, resolveFailureCount) }
|
||||
return
|
||||
}
|
||||
currentIndex = if (currentIndex >= queueIds.lastIndex) 0 else currentIndex + 1
|
||||
}
|
||||
PlayMode.Shuffle -> {
|
||||
currentIndex = nextShuffleIndex()
|
||||
}
|
||||
else -> {
|
||||
currentIndex = if (currentIndex >= queueIds.lastIndex) 0 else currentIndex + 1
|
||||
}
|
||||
}
|
||||
Timber.i(
|
||||
"Playback moveToNext: generation=%d nextIndex=%d queueSize=%d mode=%s manual=%s resolveFailureCount=%d",
|
||||
generation, currentIndex, queueIds.size, playMode.name, manual, resolveFailureCount
|
||||
)
|
||||
scope.launch { playCurrent(generation, resolveFailureCount) }
|
||||
}
|
||||
|
||||
private fun pauseAtCurrentItem() {
|
||||
progressJob?.cancel()
|
||||
progressJob = null
|
||||
val backend = activeBackend
|
||||
activeBackend = null
|
||||
transitionIsPlayingOverride = null
|
||||
when (backend) {
|
||||
PlaybackBackend.Media3 -> player.stop()
|
||||
PlaybackBackend.FfmpegAudioTrack -> stopFfmpegPlayback()
|
||||
null -> Unit
|
||||
}
|
||||
ffmpegPositionMs = 0L
|
||||
activeOutputParameters = null
|
||||
publishState(
|
||||
isPlayingOverride = false,
|
||||
backendOverride = null,
|
||||
positionOverrideMs = 0L
|
||||
)
|
||||
}
|
||||
|
||||
private fun nextShuffleIndex(): Int {
|
||||
ensureShuffleOrder()
|
||||
if (shuffleIndices.isEmpty()) return currentIndex.coerceIn(0, queueIds.lastIndex)
|
||||
if (shufflePosition >= shuffleIndices.lastIndex) {
|
||||
return reshuffleFromFirst()
|
||||
}
|
||||
shufflePosition = Math.floorMod(shufflePosition + 1, shuffleIndices.size)
|
||||
return shuffleIndices[shufflePosition]
|
||||
}
|
||||
|
||||
private fun reshuffleFromFirst(): Int {
|
||||
if (queueIds.isEmpty()) {
|
||||
shuffleIndices = IntArray(0)
|
||||
shufflePosition = -1
|
||||
return currentIndex
|
||||
}
|
||||
val indices = queueIds.indices.toMutableList()
|
||||
indices.shuffle()
|
||||
shuffleIndices = indices.toIntArray()
|
||||
shufflePosition = 0
|
||||
Timber.i("Shuffle indices rebuilt at wrap: order=%s", shuffleIndices.joinToString())
|
||||
return shuffleIndices[shufflePosition]
|
||||
}
|
||||
|
||||
private fun previousShuffleIndex(): Int {
|
||||
ensureShuffleOrder()
|
||||
if (shuffleIndices.isEmpty()) return currentIndex.coerceIn(0, queueIds.lastIndex)
|
||||
shufflePosition = Math.floorMod(shufflePosition - 1, shuffleIndices.size)
|
||||
return shuffleIndices[shufflePosition]
|
||||
}
|
||||
|
||||
private fun ensureShuffleOrder() {
|
||||
if (queueIds.isEmpty()) {
|
||||
shuffleIndices = IntArray(0)
|
||||
shufflePosition = -1
|
||||
return
|
||||
}
|
||||
if (shuffleIndices.size != queueIds.size || shuffleIndices.any { it !in queueIds.indices }) {
|
||||
buildShuffleIndices()
|
||||
return
|
||||
}
|
||||
val currentPosition = shuffleIndices.indexOf(currentIndex)
|
||||
if (currentPosition >= 0) {
|
||||
shufflePosition = currentPosition
|
||||
} else {
|
||||
scope.launch {
|
||||
playCurrent(generation)
|
||||
buildShuffleIndices()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadQueueSnapshot(generation: Long) {
|
||||
queueSnapshotJob?.cancel()
|
||||
val resolver = trackResolver ?: return
|
||||
val ids = queueIds.copyOf()
|
||||
queueSnapshotJob = scope.launch {
|
||||
val resolvedItems = withContext(Dispatchers.IO) {
|
||||
ids.map { id ->
|
||||
resolver(id)?.toQueueItem() ?: PlaybackQueueItem(id = id)
|
||||
}
|
||||
}
|
||||
if (generation == playbackGeneration) {
|
||||
queueItems = resolvedItems
|
||||
if (currentTrack?.id == queueIds.getOrNull(currentIndex)) {
|
||||
publishState()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateQueueItem(track: PlaybackTrack) {
|
||||
val index = queueIds.indexOf(track.id)
|
||||
if (index < 0) return
|
||||
val nextItems = if (queueItems.size == queueIds.size) {
|
||||
queueItems.toMutableList()
|
||||
} else {
|
||||
queueIds.map { id -> PlaybackQueueItem(id = id) }.toMutableList()
|
||||
}
|
||||
nextItems[index] = track.toQueueItem()
|
||||
queueItems = nextItems
|
||||
}
|
||||
|
||||
private fun PlaybackTrack.toQueueItem(): PlaybackQueueItem {
|
||||
return PlaybackQueueItem(
|
||||
id = id,
|
||||
title = title,
|
||||
artist = artist
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun loadCurrentTrack(generation: Long): PlaybackTrack? {
|
||||
@ -449,6 +746,7 @@ class AudioPlaybackController(context: Context) {
|
||||
resolvedTrack?.requiresFfmpeg?.toString() ?: "unknown"
|
||||
)
|
||||
currentTrack = resolvedTrack
|
||||
resolvedTrack?.let { updateQueueItem(it) }
|
||||
return currentTrack
|
||||
}
|
||||
|
||||
@ -457,11 +755,23 @@ class AudioPlaybackController(context: Context) {
|
||||
progressJob = null
|
||||
player.stop()
|
||||
stopFfmpegPlayback()
|
||||
queueSnapshotJob?.cancel()
|
||||
queueSnapshotJob = null
|
||||
activeBackend = null
|
||||
ffmpegPositionMs = 0L
|
||||
activeOutputParameters = null
|
||||
}
|
||||
|
||||
private fun stopActivePlaybackForTrackSwitch() {
|
||||
progressJob?.cancel()
|
||||
progressJob = null
|
||||
activeBackend = null
|
||||
activeOutputParameters = null
|
||||
ffmpegPositionMs = 0L
|
||||
player.stop()
|
||||
stopFfmpegPlayback()
|
||||
}
|
||||
|
||||
private fun stopFfmpegPlayback() {
|
||||
ffmpegRenderer.stop()
|
||||
}
|
||||
@ -470,7 +780,13 @@ class AudioPlaybackController(context: Context) {
|
||||
progressJob?.cancel()
|
||||
progressJob = scope.launch {
|
||||
while (generation == playbackGeneration && activeBackend == PlaybackBackend.Media3) {
|
||||
publishState()
|
||||
publishState(
|
||||
backendOverride = if (player.playbackState == Player.STATE_READY) {
|
||||
PlaybackBackend.Media3
|
||||
} else {
|
||||
null
|
||||
}
|
||||
)
|
||||
delay(PROGRESS_UPDATE_INTERVAL_MS)
|
||||
}
|
||||
}
|
||||
@ -543,7 +859,7 @@ class AudioPlaybackController(context: Context) {
|
||||
val isPlaying = isPlayingOverride ?: when (backend) {
|
||||
PlaybackBackend.Media3 -> player.isPlaying
|
||||
PlaybackBackend.FfmpegAudioTrack -> ffmpegRenderer.isPlaying()
|
||||
null -> false
|
||||
null -> transitionIsPlayingOverride ?: false
|
||||
}
|
||||
val hasError = errorMessageOverride != null
|
||||
_state.value = PlaybackState(
|
||||
@ -554,19 +870,47 @@ class AudioPlaybackController(context: Context) {
|
||||
currentAlbum = currentTrack?.album,
|
||||
isPlaying = isPlaying,
|
||||
hasQueue = queueIds.isNotEmpty(),
|
||||
queueIndex = currentIndex.takeIf { it >= 0 },
|
||||
queueIndex = displayQueueIndex(),
|
||||
queueSize = queueIds.size,
|
||||
backend = backend,
|
||||
positionMs = position.coerceAtLeast(0L),
|
||||
progressMs = position.coerceAtLeast(0L),
|
||||
durationMs = duration,
|
||||
canSeek = backend == PlaybackBackend.Media3 && !hasError,
|
||||
canSeek = backend != null && duration != null && !hasError,
|
||||
canPrevious = currentIndex > 0,
|
||||
canNext = currentIndex >= 0 && currentIndex < queueIds.lastIndex,
|
||||
queueItems = displayQueueItems(),
|
||||
playMode = playMode,
|
||||
sourceParameters = sourceParameters,
|
||||
outputParameters = outputParameters,
|
||||
errorMessage = errorMessageOverride
|
||||
)
|
||||
if (backend != null || hasError || currentTrack == null) {
|
||||
transitionIsPlayingOverride = null
|
||||
}
|
||||
}
|
||||
|
||||
private fun displayQueueItems(): List<PlaybackQueueItem> {
|
||||
val indices = displayQueueIndices()
|
||||
if (indices.isEmpty()) return emptyList()
|
||||
return indices.map { index ->
|
||||
queueItems.getOrNull(index) ?: PlaybackQueueItem(id = queueIds[index])
|
||||
}
|
||||
}
|
||||
|
||||
private fun displayQueueIndex(): Int? {
|
||||
if (currentIndex < 0) return null
|
||||
return displayQueueIndices().indexOf(currentIndex).takeIf { it >= 0 }
|
||||
}
|
||||
|
||||
private fun displayQueueIndices(): List<Int> {
|
||||
if (queueIds.isEmpty()) return emptyList()
|
||||
return if (playMode == PlayMode.Shuffle) {
|
||||
ensureShuffleOrder()
|
||||
shuffleIndices.toList()
|
||||
} else {
|
||||
queueIds.indices.toList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -587,6 +931,8 @@ data class PlaybackState(
|
||||
val canSeek: Boolean = false,
|
||||
val canPrevious: Boolean = false,
|
||||
val canNext: Boolean = false,
|
||||
val queueItems: List<PlaybackQueueItem> = emptyList(),
|
||||
val playMode: PlayMode = PlayMode.default,
|
||||
val sourceParameters: PlaybackAudioParameters? = null,
|
||||
val outputParameters: PlaybackAudioParameters? = null,
|
||||
val errorMessage: String? = null
|
||||
@ -595,6 +941,12 @@ data class PlaybackState(
|
||||
get() = !errorMessage.isNullOrBlank()
|
||||
}
|
||||
|
||||
data class PlaybackQueueItem(
|
||||
val id: Long,
|
||||
val title: String = "",
|
||||
val artist: String = ""
|
||||
)
|
||||
|
||||
enum class PlaybackBackend {
|
||||
Media3,
|
||||
FfmpegAudioTrack
|
||||
@ -698,6 +1050,7 @@ private class FfmpegPcmAudioTrackRenderer(
|
||||
|
||||
fun play(
|
||||
track: PlaybackTrack,
|
||||
startPositionMs: Long = 0L,
|
||||
onOutputReady: (PlaybackAudioParameters) -> Unit,
|
||||
onProgress: (Long) -> Unit,
|
||||
onEnded: () -> Unit,
|
||||
@ -741,11 +1094,17 @@ private class FfmpegPcmAudioTrackRenderer(
|
||||
)
|
||||
val input = openFfmpegInput(context, track.uri)
|
||||
inputHandle = input
|
||||
val seekArgs = if (startPositionMs > 0L) {
|
||||
arrayOf("-ss", (startPositionMs / 1000.0).toString())
|
||||
} else {
|
||||
emptyArray()
|
||||
}
|
||||
val ffmpegArgs = arrayOf(
|
||||
"-hide_banner",
|
||||
"-y",
|
||||
"-loglevel",
|
||||
"error",
|
||||
*seekArgs,
|
||||
"-i",
|
||||
input.path,
|
||||
"-vn",
|
||||
@ -960,7 +1319,18 @@ private class FfmpegPcmAudioTrackRenderer(
|
||||
audioTrack = null
|
||||
if (!stopped.get()) {
|
||||
if (writtenBytes == 0L) {
|
||||
val durationMs = track.durationMs?.takeIf { it > 0L }
|
||||
if (isFfmpegSeekAtPlayableEnd(startPositionMs, durationMs)) {
|
||||
Timber.i(
|
||||
"FFmpeg produced no PCM at seek end; treating as playback ended: trackId=%d startPositionMs=%d durationMs=%s",
|
||||
track.id,
|
||||
startPositionMs,
|
||||
durationMs?.toString() ?: "unknown"
|
||||
)
|
||||
onEnded()
|
||||
} else {
|
||||
onError("FFmpeg produced no PCM output")
|
||||
}
|
||||
} else {
|
||||
onEnded()
|
||||
}
|
||||
@ -1255,6 +1625,15 @@ internal fun isInvalidMedia3Duration(durationMs: Long): Boolean {
|
||||
return durationMs <= 0L
|
||||
}
|
||||
|
||||
internal fun shouldFallbackForInvalidMedia3Duration(playbackState: Int, durationMs: Long): Boolean {
|
||||
return playbackState == Player.STATE_READY && isInvalidMedia3Duration(durationMs)
|
||||
}
|
||||
|
||||
internal fun isFfmpegSeekAtPlayableEnd(startPositionMs: Long, durationMs: Long?): Boolean {
|
||||
val duration = durationMs?.takeIf { it > 0L } ?: return false
|
||||
return startPositionMs >= (duration - FFMPEG_END_SEEK_TOLERANCE_MS).coerceAtLeast(0L)
|
||||
}
|
||||
|
||||
private fun Throwable.playbackCauseChain(): String {
|
||||
return generateSequence(this) { it.cause }
|
||||
.take(6)
|
||||
@ -1385,5 +1764,6 @@ private fun supportsAudioTrack(sampleRate: Int, encoding: Int): Boolean {
|
||||
|
||||
private const val DEFAULT_OUTPUT_SAMPLE_RATE = 48_000
|
||||
private const val PROGRESS_UPDATE_INTERVAL_MS = 1_000L
|
||||
private const val FFMPEG_END_SEEK_TOLERANCE_MS = 1_000L
|
||||
private const val PCM_DEBUG_INITIAL_CHUNKS = 5
|
||||
private const val LOG_PREVIEW_LIMIT = 512
|
||||
|
||||
@ -19,6 +19,7 @@ import android.os.IBinder
|
||||
import com.audio.vibe.MainActivity
|
||||
import com.audio.vibe.R
|
||||
import com.audio.vibe.domain.model.PlaybackTrack
|
||||
import com.audio.vibe.domain.model.PlayMode
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
@ -44,6 +45,30 @@ class AudioPlaybackService : Service() {
|
||||
return controller.toggleCurrent()
|
||||
}
|
||||
|
||||
override fun playNext() {
|
||||
controller.playNext()
|
||||
}
|
||||
|
||||
override fun playPrevious() {
|
||||
controller.playPrevious()
|
||||
}
|
||||
|
||||
override fun playQueueIndex(index: Int): Boolean {
|
||||
return controller.playQueueIndex(index)
|
||||
}
|
||||
|
||||
override fun seekTo(positionMs: Long): Boolean {
|
||||
return controller.seekTo(positionMs)
|
||||
}
|
||||
|
||||
override fun setPlayMode(mode: PlayMode) {
|
||||
controller.setPlayMode(mode)
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
controller.stop()
|
||||
}
|
||||
|
||||
override fun playQueue(
|
||||
queueIds: LongArray,
|
||||
startTrackId: Long,
|
||||
@ -217,37 +242,54 @@ class AudioPlaybackService : Service() {
|
||||
.setMediaSession(mediaSession.sessionToken)
|
||||
.setShowActionsInCompactView(0, 1, 2)
|
||||
)
|
||||
.addAction(
|
||||
Notification.Action.Builder(
|
||||
R.drawable.ic_notification_audio,
|
||||
ACTION_LABEL_PREVIOUS,
|
||||
servicePendingIntent(ACTION_PREVIOUS, REQUEST_PREVIOUS)
|
||||
).build()
|
||||
)
|
||||
.addAction(
|
||||
Notification.Action.Builder(
|
||||
R.drawable.ic_notification_audio,
|
||||
if (state.isPlaying) ACTION_LABEL_PAUSE else ACTION_LABEL_PLAY,
|
||||
servicePendingIntent(ACTION_TOGGLE, REQUEST_TOGGLE)
|
||||
).build()
|
||||
)
|
||||
.addAction(
|
||||
Notification.Action.Builder(
|
||||
R.drawable.ic_notification_audio,
|
||||
ACTION_LABEL_NEXT,
|
||||
servicePendingIntent(ACTION_NEXT, REQUEST_NEXT)
|
||||
).build()
|
||||
)
|
||||
.addAction(
|
||||
Notification.Action.Builder(
|
||||
R.drawable.ic_notification_audio,
|
||||
getString(R.string.stop),
|
||||
servicePendingIntent(ACTION_STOP, REQUEST_STOP)
|
||||
).build()
|
||||
)
|
||||
.apply {
|
||||
playbackNotificationActions(state.isPlaying).forEach { action ->
|
||||
addAction(buildNotificationAction(action))
|
||||
}
|
||||
}
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun buildNotificationAction(
|
||||
action: PlaybackNotificationAction
|
||||
): Notification.Action {
|
||||
val (icon, label, intentAction, requestCode) = when (action) {
|
||||
PlaybackNotificationAction.Previous -> NotificationActionSpec(
|
||||
icon = R.drawable.ic_notification_previous,
|
||||
label = ACTION_LABEL_PREVIOUS,
|
||||
intentAction = ACTION_PREVIOUS,
|
||||
requestCode = REQUEST_PREVIOUS
|
||||
)
|
||||
|
||||
PlaybackNotificationAction.Play -> NotificationActionSpec(
|
||||
icon = R.drawable.ic_notification_play,
|
||||
label = ACTION_LABEL_PLAY,
|
||||
intentAction = ACTION_TOGGLE,
|
||||
requestCode = REQUEST_TOGGLE
|
||||
)
|
||||
|
||||
PlaybackNotificationAction.Pause -> NotificationActionSpec(
|
||||
icon = R.drawable.ic_notification_pause,
|
||||
label = ACTION_LABEL_PAUSE,
|
||||
intentAction = ACTION_TOGGLE,
|
||||
requestCode = REQUEST_TOGGLE
|
||||
)
|
||||
|
||||
PlaybackNotificationAction.Next -> NotificationActionSpec(
|
||||
icon = R.drawable.ic_notification_next,
|
||||
label = ACTION_LABEL_NEXT,
|
||||
intentAction = ACTION_NEXT,
|
||||
requestCode = REQUEST_NEXT
|
||||
)
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
return Notification.Action.Builder(
|
||||
icon,
|
||||
label,
|
||||
servicePendingIntent(intentAction, requestCode)
|
||||
).build()
|
||||
}
|
||||
|
||||
private fun updateMediaSession(state: PlaybackMediaSessionState) {
|
||||
if (!::mediaSession.isInitialized) return
|
||||
val actions = (PlatformPlaybackState.ACTION_PLAY or
|
||||
@ -314,9 +356,22 @@ class AudioPlaybackService : Service() {
|
||||
|
||||
companion object {
|
||||
suspend fun startAndBindController(context: Context): PlaybackServiceController? {
|
||||
return bindController(context = context, startService = true)
|
||||
}
|
||||
|
||||
suspend fun bindControllerIfRunning(context: Context): PlaybackServiceController? {
|
||||
return bindController(context = context, startService = false)
|
||||
}
|
||||
|
||||
private suspend fun bindController(
|
||||
context: Context,
|
||||
startService: Boolean
|
||||
): PlaybackServiceController? {
|
||||
val appContext = context.applicationContext
|
||||
val intent = Intent(appContext, AudioPlaybackService::class.java)
|
||||
if (startService) {
|
||||
appContext.startService(intent)
|
||||
}
|
||||
return suspendCancellableCoroutine { continuation ->
|
||||
var connection: ServiceConnection? = null
|
||||
connection = object : ServiceConnection {
|
||||
@ -344,7 +399,8 @@ class AudioPlaybackService : Service() {
|
||||
}
|
||||
}
|
||||
}
|
||||
val bound = appContext.bindService(intent, connection, BIND_AUTO_CREATE)
|
||||
val flags = if (startService) Context.BIND_AUTO_CREATE else 0
|
||||
val bound = appContext.bindService(intent, connection, flags)
|
||||
if (!bound && continuation.isActive) {
|
||||
continuation.resume(null)
|
||||
}
|
||||
@ -371,3 +427,10 @@ private const val REQUEST_TOGGLE = 1
|
||||
private const val REQUEST_NEXT = 2
|
||||
private const val REQUEST_PREVIOUS = 3
|
||||
private const val REQUEST_STOP = 4
|
||||
|
||||
private data class NotificationActionSpec(
|
||||
val icon: Int,
|
||||
val label: String,
|
||||
val intentAction: String,
|
||||
val requestCode: Int
|
||||
)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.audio.vibe.data.playback
|
||||
|
||||
import com.audio.vibe.domain.model.PlaybackTrack
|
||||
import com.audio.vibe.domain.model.PlayMode
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface PlaybackServiceController {
|
||||
@ -8,6 +9,18 @@ interface PlaybackServiceController {
|
||||
|
||||
fun toggleCurrent(): Boolean
|
||||
|
||||
fun playNext() {}
|
||||
|
||||
fun playPrevious() {}
|
||||
|
||||
fun playQueueIndex(index: Int): Boolean = false
|
||||
|
||||
fun seekTo(positionMs: Long): Boolean = false
|
||||
|
||||
fun setPlayMode(mode: PlayMode) {}
|
||||
|
||||
fun stop() {}
|
||||
|
||||
fun playQueue(
|
||||
queueIds: LongArray,
|
||||
startTrackId: Long,
|
||||
|
||||
@ -22,6 +22,21 @@ internal data class PlaybackNotificationVisibleState(
|
||||
val errorMessage: String?
|
||||
)
|
||||
|
||||
internal enum class PlaybackNotificationAction {
|
||||
Previous,
|
||||
Play,
|
||||
Pause,
|
||||
Next
|
||||
}
|
||||
|
||||
internal fun playbackNotificationActions(isPlaying: Boolean): List<PlaybackNotificationAction> {
|
||||
return listOf(
|
||||
PlaybackNotificationAction.Previous,
|
||||
if (isPlaying) PlaybackNotificationAction.Pause else PlaybackNotificationAction.Play,
|
||||
PlaybackNotificationAction.Next
|
||||
)
|
||||
}
|
||||
|
||||
internal fun PlaybackState.toMediaSessionState(): PlaybackMediaSessionState {
|
||||
return PlaybackMediaSessionState(
|
||||
currentId = currentId,
|
||||
|
||||
14
app/src/main/java/com/audio/vibe/domain/model/PlayMode.kt
Normal file
14
app/src/main/java/com/audio/vibe/domain/model/PlayMode.kt
Normal file
@ -0,0 +1,14 @@
|
||||
package com.audio.vibe.domain.model
|
||||
|
||||
enum class PlayMode {
|
||||
ListCycle,
|
||||
ListOnce,
|
||||
RepeatOne,
|
||||
Shuffle;
|
||||
|
||||
fun next(): PlayMode = entries[(ordinal + 1) % entries.size]
|
||||
|
||||
companion object {
|
||||
val default = ListCycle
|
||||
}
|
||||
}
|
||||
@ -85,12 +85,13 @@ fun VibeScreen(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(bg)
|
||||
.padding(horizontal = 20.dp)
|
||||
|
||||
) {
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 20.dp)
|
||||
.height(56.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
||||
@ -81,6 +81,7 @@ fun HomeScreen(
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 20.dp)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.spacedBy(18.dp)
|
||||
) {
|
||||
|
||||
@ -139,6 +139,7 @@ data class AppStrings(
|
||||
val scanAgain: String,
|
||||
val scanFolder: String,
|
||||
val resetLibrary: String,
|
||||
val loadingLibrary: String,
|
||||
val scanning: String,
|
||||
val scannedCount: String,
|
||||
val cachedLibrary: String,
|
||||
@ -148,7 +149,11 @@ data class AppStrings(
|
||||
val tracks: String,
|
||||
val highRes: String,
|
||||
val formats: String,
|
||||
val unknown: String
|
||||
val unknown: String,
|
||||
val play: String,
|
||||
val pause: String,
|
||||
val nextTrack: String,
|
||||
val previousTrack: String
|
||||
)
|
||||
|
||||
val LocalAppStrings = staticCompositionLocalOf { fallbackStrings }
|
||||
@ -296,6 +301,7 @@ private fun android.content.res.Resources.toAppStrings(): AppStrings = AppString
|
||||
scanAgain = getString(R.string.scan_again),
|
||||
scanFolder = getString(R.string.scan_folder),
|
||||
resetLibrary = getString(R.string.reset_library),
|
||||
loadingLibrary = getString(R.string.loading_library),
|
||||
scanning = getString(R.string.scanning),
|
||||
scannedCount = getString(R.string.scanned_count),
|
||||
cachedLibrary = getString(R.string.cached_library),
|
||||
@ -305,7 +311,11 @@ private fun android.content.res.Resources.toAppStrings(): AppStrings = AppString
|
||||
tracks = getString(R.string.tracks),
|
||||
highRes = getString(R.string.high_res),
|
||||
formats = getString(R.string.formats),
|
||||
unknown = getString(R.string.unknown)
|
||||
unknown = getString(R.string.unknown),
|
||||
play = getString(R.string.play),
|
||||
pause = getString(R.string.pause),
|
||||
nextTrack = getString(R.string.next_track),
|
||||
previousTrack = getString(R.string.previous_track)
|
||||
)
|
||||
|
||||
private val fallbackStrings = AppStrings(
|
||||
@ -409,6 +419,7 @@ private val fallbackStrings = AppStrings(
|
||||
scanAgain = "",
|
||||
scanFolder = "",
|
||||
resetLibrary = "",
|
||||
loadingLibrary = "",
|
||||
scanning = "",
|
||||
scannedCount = "",
|
||||
cachedLibrary = "",
|
||||
@ -418,5 +429,9 @@ private val fallbackStrings = AppStrings(
|
||||
tracks = "",
|
||||
highRes = "",
|
||||
formats = "",
|
||||
unknown = "Unknown"
|
||||
unknown = "Unknown",
|
||||
play = "Play",
|
||||
pause = "Pause",
|
||||
nextTrack = "Next",
|
||||
previousTrack = "Previous"
|
||||
)
|
||||
|
||||
@ -1,9 +1,16 @@
|
||||
package com.audio.vibe.ui.musicmanager
|
||||
|
||||
class LazyPlaybackControllerProvider<T>(
|
||||
private val create: suspend () -> T?
|
||||
private val create: suspend () -> T?,
|
||||
private val peek: suspend () -> T?
|
||||
) {
|
||||
constructor(create: suspend () -> T?) : this(create, { null })
|
||||
|
||||
suspend fun get(): T? {
|
||||
return create()
|
||||
}
|
||||
|
||||
suspend fun getIfRunning(): T? {
|
||||
return peek()
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.background
|
||||
@ -42,6 +43,7 @@ import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -55,6 +57,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.content.ContextCompat
|
||||
@ -73,20 +76,26 @@ import com.audio.vibe.ui.components.VibeCard
|
||||
import com.audio.vibe.ui.components.VibeScreen
|
||||
import com.audio.vibe.ui.i18n.AppStrings
|
||||
import com.audio.vibe.ui.i18n.LocalAppStrings
|
||||
import com.audio.vibe.ui.player.MiniPlayerBar
|
||||
import com.audio.vibe.ui.theme.AudioVibeTheme
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Composable
|
||||
fun MusicManagerScreen(onBack: () -> Unit = {}, toEditor: () -> Unit = {}) {
|
||||
fun MusicManagerScreen(onBack: () -> Unit = {}, toEditor: () -> Unit = {}, toPlayer: () -> Unit = {}) {
|
||||
val context = LocalContext.current
|
||||
val repository = remember(context) {
|
||||
MusicScannerRepositoryProvider.get(context.applicationContext)
|
||||
}
|
||||
val playbackControllerProvider = remember(context) {
|
||||
LazyPlaybackControllerProvider {
|
||||
LazyPlaybackControllerProvider(
|
||||
create = {
|
||||
AudioPlaybackService.startAndBindController(context.applicationContext)
|
||||
},
|
||||
peek = {
|
||||
AudioPlaybackService.bindControllerIfRunning(context.applicationContext)
|
||||
}
|
||||
)
|
||||
}
|
||||
val viewModel: MusicManagerViewModel = viewModel(
|
||||
factory = MusicManagerViewModelFactory(repository, playbackControllerProvider)
|
||||
@ -141,17 +150,6 @@ fun MusicManagerScreen(onBack: () -> Unit = {}, toEditor: () -> Unit = {}) {
|
||||
tint = AudioVibeColors.Muted
|
||||
)
|
||||
}
|
||||
// IconButton(
|
||||
// onClick = {
|
||||
// if (context.hasPermission(permission)) {
|
||||
// viewModel.onEvent(MusicManagerEvent.ScanRequested)
|
||||
// } else {
|
||||
// permissionLauncher.launch(permission)
|
||||
// }
|
||||
// }
|
||||
// ) {
|
||||
// Icon(Icons.Default.Sync, contentDescription = strings.scanAgain, tint = AudioVibeColors.Primary)
|
||||
// }
|
||||
},
|
||||
) {
|
||||
MusicManagerContent(
|
||||
@ -168,7 +166,8 @@ fun MusicManagerScreen(onBack: () -> Unit = {}, toEditor: () -> Unit = {}) {
|
||||
},
|
||||
onRequestPermission = { permissionLauncher.launch(permission) },
|
||||
onScanFolder = { folderLauncher.launch(null) },
|
||||
toEditor = toEditor
|
||||
toEditor = toEditor,
|
||||
toPlayer = toPlayer,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -181,7 +180,8 @@ private fun MusicManagerContent(
|
||||
onPlayTrack: (Long) -> Unit,
|
||||
onRequestPermission: () -> Unit,
|
||||
onScanFolder: () -> Unit,
|
||||
toEditor: () -> Unit
|
||||
toEditor: () -> Unit,
|
||||
toPlayer: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val audioPermission = rememberAudioPermission()
|
||||
@ -192,10 +192,19 @@ private fun MusicManagerContent(
|
||||
onRequestPermission()
|
||||
}
|
||||
}
|
||||
val miniPlayerState = uiState.miniPlayerState
|
||||
val listBottomPadding = if (miniPlayerState.isVisible) 64.dp else 0.dp
|
||||
LaunchedEffect(miniPlayerState.errorMessage) {
|
||||
miniPlayerState.errorMessage?.takeIf { it.isNotBlank() }?.let { message ->
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(bottom = 16.dp),
|
||||
.padding(start = 20.dp, end = 20.dp, bottom = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp)
|
||||
) {
|
||||
ScanActions(
|
||||
@ -203,6 +212,8 @@ private fun MusicManagerContent(
|
||||
onScanFolder = onScanFolder
|
||||
)
|
||||
when (val state = uiState.libraryState) {
|
||||
MusicLibraryState.Loading -> LoadingLibraryCard()
|
||||
|
||||
is MusicLibraryState.Scanning -> ScanningLibrary(
|
||||
scanned = state.scanned,
|
||||
stats = state.stats,
|
||||
@ -212,7 +223,8 @@ private fun MusicManagerContent(
|
||||
playingId = uiState.playingId,
|
||||
onEvent = onEvent,
|
||||
onPlayTrack = onPlayTrack,
|
||||
toEditor = toEditor
|
||||
toEditor = toEditor,
|
||||
bottomPadding = listBottomPadding
|
||||
)
|
||||
|
||||
MusicLibraryState.Empty -> EmptyLibraryCard(onScanDevice)
|
||||
@ -226,11 +238,22 @@ private fun MusicManagerContent(
|
||||
playingId = uiState.playingId,
|
||||
onEvent = onEvent,
|
||||
onPlayTrack = onPlayTrack,
|
||||
toEditor = toEditor
|
||||
toEditor = toEditor,
|
||||
bottomPadding = listBottomPadding
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MiniPlayerBar(
|
||||
state = miniPlayerState,
|
||||
onPlayPause = { onEvent(MusicManagerEvent.MiniPlayerPlayPauseToggled) },
|
||||
onSkipPrevious = { onEvent(MusicManagerEvent.MiniPlayerSkipPrevious) },
|
||||
onSkipNext = { onEvent(MusicManagerEvent.MiniPlayerSkipNext) },
|
||||
onNavigateToPlayer = toPlayer,
|
||||
modifier = Modifier.align(Alignment.BottomCenter)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -260,7 +283,8 @@ private fun LibrarySearchAndList(
|
||||
playingId: Long?,
|
||||
onEvent: (MusicManagerEvent) -> Unit,
|
||||
onPlayTrack: (Long) -> Unit,
|
||||
toEditor: () -> Unit
|
||||
toEditor: () -> Unit,
|
||||
bottomPadding: Dp = 0.dp
|
||||
) {
|
||||
val strings = LocalAppStrings.current
|
||||
OutlinedTextField(
|
||||
@ -271,15 +295,12 @@ private fun LibrarySearchAndList(
|
||||
leadingIcon = { Icon(Icons.Default.Search, null) },
|
||||
placeholder = { Text(strings.searchSongArtist) }
|
||||
)
|
||||
// CategoryTabs(
|
||||
// selected = category,
|
||||
// onSelected = { onEvent(MusicManagerEvent.CategoryChanged(it)) }
|
||||
// )
|
||||
TrackList(
|
||||
tracks = tracks,
|
||||
playingId = playingId,
|
||||
onPlay = onPlayTrack,
|
||||
toEditor = toEditor
|
||||
toEditor = toEditor,
|
||||
bottomPadding = bottomPadding
|
||||
)
|
||||
}
|
||||
|
||||
@ -293,7 +314,8 @@ private fun ScanningLibrary(
|
||||
playingId: Long?,
|
||||
onEvent: (MusicManagerEvent) -> Unit,
|
||||
onPlayTrack: (Long) -> Unit,
|
||||
toEditor: () -> Unit
|
||||
toEditor: () -> Unit,
|
||||
bottomPadding: Dp = 0.dp
|
||||
) {
|
||||
val visibleStats = stats ?: MusicLibraryStats.Empty
|
||||
ScanningCard(scanned = scanned)
|
||||
@ -305,10 +327,31 @@ private fun ScanningLibrary(
|
||||
playingId = playingId,
|
||||
onEvent = onEvent,
|
||||
onPlayTrack = onPlayTrack,
|
||||
toEditor = toEditor
|
||||
toEditor = toEditor,
|
||||
bottomPadding = bottomPadding
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LoadingLibraryCard() {
|
||||
val strings = LocalAppStrings.current
|
||||
VibeCard(modifier = Modifier.fillMaxWidth()) {
|
||||
Row(modifier = Modifier.padding(14.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
CircularProgressIndicator(
|
||||
color = AudioVibeColors.Primary,
|
||||
modifier = Modifier.size(34.dp),
|
||||
strokeWidth = 3.dp
|
||||
)
|
||||
Text(
|
||||
text = strings.loadingLibrary,
|
||||
color = AudioVibeColors.Muted,
|
||||
fontSize = 14.sp,
|
||||
modifier = Modifier.padding(start = 14.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ScanningCard(scanned: Int) {
|
||||
val strings = LocalAppStrings.current
|
||||
@ -488,11 +531,13 @@ private fun TrackList(
|
||||
tracks: LazyPagingItems<ScannedAudioTrack>,
|
||||
playingId: Long?,
|
||||
onPlay: (Long) -> Unit,
|
||||
toEditor: () -> Unit
|
||||
toEditor: () -> Unit,
|
||||
bottomPadding: Dp = 0.dp
|
||||
) {
|
||||
LazyColumn(
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = androidx.compose.foundation.layout.PaddingValues(bottom = bottomPadding)
|
||||
) {
|
||||
items(
|
||||
count = tracks.itemCount,
|
||||
@ -507,7 +552,7 @@ private fun TrackList(
|
||||
track = track,
|
||||
playing = playingId == track.id,
|
||||
onPlay = { onPlay(track.id) },
|
||||
toEditor = toEditor
|
||||
toEditor = toEditor,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -567,7 +612,6 @@ private fun TrackRow(
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
SpecChip(track.format)
|
||||
SpecChip(track.sampleRateLabel(strings))
|
||||
// SpecChip(track.durationLabel())
|
||||
}
|
||||
}
|
||||
IconButton(onClick = onPlay) {
|
||||
@ -636,13 +680,6 @@ private fun ScannedAudioTrack.sampleRateLabel(strings: AppStrings): String {
|
||||
return bitDepth?.let { "$label $it" } ?: label
|
||||
}
|
||||
|
||||
private fun ScannedAudioTrack.durationLabel(): String {
|
||||
val totalSeconds = (durationMs / 1000).coerceAtLeast(0)
|
||||
val minutes = totalSeconds / 60
|
||||
val seconds = totalSeconds % 60
|
||||
return "$minutes:${seconds.toString().padStart(2, '0')}"
|
||||
}
|
||||
|
||||
private fun Long.sizeLabel(): String {
|
||||
if (this <= 0L) return "-"
|
||||
val mb = this / 1024f / 1024f
|
||||
@ -695,7 +732,8 @@ private fun MusicManagerScreenPreview() {
|
||||
onPlayTrack = {},
|
||||
onRequestPermission = {},
|
||||
onScanFolder = {},
|
||||
toEditor = {}
|
||||
toEditor = {},
|
||||
toPlayer = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import com.audio.vibe.domain.model.ScannedAudioTrack
|
||||
import com.audio.vibe.domain.repository.MusicLibrarySort
|
||||
import com.audio.vibe.domain.repository.MusicLibrarySummary
|
||||
import com.audio.vibe.domain.repository.MusicScannerRepository
|
||||
import com.audio.vibe.ui.player.MiniPlayerState
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.Job
|
||||
@ -42,6 +43,7 @@ class MusicManagerViewModel(
|
||||
|
||||
init {
|
||||
loadCachedLibrary()
|
||||
observeCurrentPlayback()
|
||||
}
|
||||
|
||||
fun onEvent(event: MusicManagerEvent) {
|
||||
@ -54,11 +56,18 @@ class MusicManagerViewModel(
|
||||
}
|
||||
is MusicManagerEvent.CategoryChanged -> _uiState.update { it.copy(category = event.category) }
|
||||
is MusicManagerEvent.PlayToggled -> togglePlayback(event.trackId)
|
||||
MusicManagerEvent.MiniPlayerPlayPauseToggled -> toggleMiniPlayer()
|
||||
MusicManagerEvent.MiniPlayerSkipNext -> skipNext()
|
||||
MusicManagerEvent.MiniPlayerSkipPrevious -> skipPrevious()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun ensurePlaybackController(): PlaybackServiceController? {
|
||||
val controller = playbackControllerProvider?.get()
|
||||
private suspend fun ensurePlaybackController(startIfNeeded: Boolean = true): PlaybackServiceController? {
|
||||
val controller = if (startIfNeeded) {
|
||||
playbackControllerProvider?.get()
|
||||
} else {
|
||||
playbackControllerProvider?.getIfRunning()
|
||||
}
|
||||
if (controller != null && observedPlaybackController !== controller) {
|
||||
playbackStateJob?.cancel()
|
||||
observedPlaybackController = controller
|
||||
@ -69,14 +78,42 @@ class MusicManagerViewModel(
|
||||
return controller
|
||||
}
|
||||
|
||||
private fun observeCurrentPlayback() {
|
||||
viewModelScope.launch {
|
||||
ensurePlaybackController(startIfNeeded = false)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun observePlayback(controller: PlaybackServiceController) {
|
||||
controller.state.collect { playbackState ->
|
||||
_uiState.update { state ->
|
||||
state.copy(playingId = playbackState.currentId.takeIf { playbackState.isPlaying })
|
||||
state.copy(
|
||||
playingId = playbackState.currentId.takeIf { playbackState.isPlaying },
|
||||
miniPlayerState = MiniPlayerState.from(playbackState)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleMiniPlayer() {
|
||||
viewModelScope.launch {
|
||||
val controller = playbackControllerProvider?.get() ?: return@launch
|
||||
controller.toggleCurrent()
|
||||
}
|
||||
}
|
||||
|
||||
private fun skipNext() {
|
||||
viewModelScope.launch {
|
||||
playbackControllerProvider?.get()?.playNext()
|
||||
}
|
||||
}
|
||||
|
||||
private fun skipPrevious() {
|
||||
viewModelScope.launch {
|
||||
playbackControllerProvider?.get()?.playPrevious()
|
||||
}
|
||||
}
|
||||
|
||||
private fun togglePlayback(trackId: Long) {
|
||||
viewModelScope.launch {
|
||||
val controller = ensurePlaybackController()
|
||||
@ -201,10 +238,12 @@ class MusicManagerViewModel(
|
||||
if (scanJob == jobToCancel) {
|
||||
scanJob = null
|
||||
}
|
||||
ensurePlaybackController(startIfNeeded = false)?.stop()
|
||||
repository.resetLibrary()
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
playingId = null,
|
||||
miniPlayerState = MiniPlayerState.Hidden,
|
||||
query = "",
|
||||
libraryState = MusicLibraryState.Empty
|
||||
)
|
||||
@ -248,6 +287,10 @@ class MusicManagerViewModel(
|
||||
state.copy(libraryState = summary.toLibraryState(fromCache = true, query = query))
|
||||
}
|
||||
|
||||
MusicLibraryState.Loading -> {
|
||||
state.copy(libraryState = summary.toLibraryState(fromCache = true, query = query))
|
||||
}
|
||||
|
||||
is MusicLibraryState.Error -> state
|
||||
}
|
||||
}
|
||||
@ -274,6 +317,9 @@ sealed interface MusicManagerEvent {
|
||||
data class QueryChanged(val query: String) : MusicManagerEvent
|
||||
data class CategoryChanged(val category: MusicCategory) : MusicManagerEvent
|
||||
data class PlayToggled(val trackId: Long) : MusicManagerEvent
|
||||
data object MiniPlayerPlayPauseToggled : MusicManagerEvent
|
||||
data object MiniPlayerSkipNext : MusicManagerEvent
|
||||
data object MiniPlayerSkipPrevious : MusicManagerEvent
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@ -281,10 +327,13 @@ data class MusicManagerUiState(
|
||||
val query: String = "",
|
||||
val category: MusicCategory = MusicCategory.Tracks,
|
||||
val playingId: Long? = null,
|
||||
val libraryState: MusicLibraryState = MusicLibraryState.Empty
|
||||
val miniPlayerState: MiniPlayerState = MiniPlayerState.Hidden,
|
||||
val libraryState: MusicLibraryState = MusicLibraryState.Loading
|
||||
)
|
||||
|
||||
sealed interface MusicLibraryState {
|
||||
data object Loading : MusicLibraryState
|
||||
|
||||
data class Scanning(
|
||||
val scanned: Int,
|
||||
val stats: MusicLibraryStats?
|
||||
|
||||
162
app/src/main/java/com/audio/vibe/ui/player/CoverImageLoader.kt
Normal file
162
app/src/main/java/com/audio/vibe/ui/player/CoverImageLoader.kt
Normal file
@ -0,0 +1,162 @@
|
||||
package com.audio.vibe.ui.player
|
||||
|
||||
import android.graphics.BitmapFactory
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.net.Uri
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.MusicNote
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.audio.vibe.ui.components.AudioVibeColors
|
||||
import java.io.File
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun CoverImage(
|
||||
sourcePath: String?,
|
||||
uri: Uri?,
|
||||
modifier: Modifier = Modifier,
|
||||
cornerRadius: androidx.compose.ui.unit.Dp = 20.dp
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val shape = RoundedCornerShape(cornerRadius)
|
||||
var artwork by remember { mutableStateOf<CoverArtwork?>(null) }
|
||||
var requestedKey by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
LaunchedEffect(sourcePath, uri) {
|
||||
val key = sourcePath ?: uri?.toString()
|
||||
requestedKey = key
|
||||
val resolved = withContext(Dispatchers.IO) {
|
||||
resolveCoverArtwork(context, sourcePath, uri)
|
||||
}
|
||||
if (requestedKey == key) {
|
||||
artwork = resolved
|
||||
}
|
||||
}
|
||||
|
||||
Box(modifier = modifier.clip(shape)) {
|
||||
DefaultCoverPlaceholder(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
cornerRadius = 0.dp
|
||||
)
|
||||
Crossfade(
|
||||
targetState = artwork,
|
||||
animationSpec = tween(durationMillis = 260),
|
||||
label = "coverArtwork"
|
||||
) { currentArtwork ->
|
||||
if (currentArtwork != null) {
|
||||
Image(
|
||||
bitmap = currentArtwork.bitmap.asImageBitmap(),
|
||||
contentDescription = "专辑封面",
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DefaultCoverPlaceholder(
|
||||
modifier: Modifier = Modifier,
|
||||
cornerRadius: androidx.compose.ui.unit.Dp = 20.dp
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.clip(RoundedCornerShape(cornerRadius))
|
||||
.background(
|
||||
Brush.linearGradient(
|
||||
colors = listOf(
|
||||
AudioVibeColors.Primary,
|
||||
AudioVibeColors.Purple
|
||||
)
|
||||
)
|
||||
),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.MusicNote,
|
||||
contentDescription = null,
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(64.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private data class CoverArtwork(
|
||||
val key: String,
|
||||
val bitmap: android.graphics.Bitmap
|
||||
)
|
||||
|
||||
private fun resolveCoverArtwork(
|
||||
context: android.content.Context,
|
||||
sourcePath: String?,
|
||||
uri: Uri?
|
||||
): CoverArtwork? {
|
||||
sourcePath?.let { path ->
|
||||
findExternalCover(path)?.let { coverPath ->
|
||||
BitmapFactory.decodeFile(coverPath)?.let { bitmap ->
|
||||
return CoverArtwork("external:$coverPath", bitmap)
|
||||
}
|
||||
}
|
||||
}
|
||||
uri?.let { coverUri ->
|
||||
extractEmbeddedCover(context, coverUri)?.let { bitmap ->
|
||||
return CoverArtwork("embedded:$coverUri", bitmap)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private val coverFileNames = listOf(
|
||||
"folder.jpg", "cover.jpg", "Folder.jpg", "Cover.jpg",
|
||||
"folder.png", "cover.png", "album.jpg", "Album.jpg",
|
||||
"front.jpg", "Front.jpg", "albumart.jpg"
|
||||
)
|
||||
|
||||
private fun findExternalCover(sourcePath: String): String? {
|
||||
val file = File(sourcePath)
|
||||
val parent = file.parentFile ?: return null
|
||||
for (name in coverFileNames) {
|
||||
val cover = File(parent, name)
|
||||
if (cover.exists() && cover.length() > 0) return cover.absolutePath
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun extractEmbeddedCover(context: android.content.Context, uri: Uri): android.graphics.Bitmap? {
|
||||
return try {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
retriever.setDataSource(context, uri)
|
||||
val picture = retriever.embeddedPicture
|
||||
retriever.release()
|
||||
picture?.let { data ->
|
||||
BitmapFactory.decodeByteArray(data, 0, data.size)
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
189
app/src/main/java/com/audio/vibe/ui/player/MiniPlayerBar.kt
Normal file
189
app/src/main/java/com/audio/vibe/ui/player/MiniPlayerBar.kt
Normal file
@ -0,0 +1,189 @@
|
||||
package com.audio.vibe.ui.player
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.basicMarquee
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.MusicNote
|
||||
import androidx.compose.material.icons.filled.Pause
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.SkipNext
|
||||
import androidx.compose.material.icons.filled.SkipPrevious
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.audio.vibe.ui.components.AudioVibeColors
|
||||
import com.audio.vibe.ui.i18n.LocalAppStrings
|
||||
|
||||
@Composable
|
||||
fun MiniPlayerBar(
|
||||
state: MiniPlayerState,
|
||||
onPlayPause: () -> Unit,
|
||||
onSkipPrevious: () -> Unit,
|
||||
onSkipNext: () -> Unit,
|
||||
onNavigateToPlayer: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
if (!state.isVisible) return
|
||||
|
||||
val strings = LocalAppStrings.current
|
||||
val topShape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)
|
||||
val animatedProgress by animateFloatAsState(
|
||||
targetValue = state.progressFraction,
|
||||
animationSpec = tween(durationMillis = 300),
|
||||
label = "progress"
|
||||
)
|
||||
val showPause = state.isPlaying
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.shadow(8.dp, topShape)
|
||||
.clip(topShape)
|
||||
.background(AudioVibeColors.Surface)
|
||||
.clickable(onClick = onNavigateToPlayer)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(64.dp)
|
||||
.padding(horizontal = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(44.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(AudioVibeColors.PrimarySoft),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.MusicNote,
|
||||
contentDescription = null,
|
||||
tint = AudioVibeColors.Primary,
|
||||
modifier = Modifier.size(22.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.width(12.dp))
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
MiniPlayerMarqueeText(
|
||||
text = state.title.ifBlank { strings.unknown },
|
||||
color = if (state.hasError) AudioVibeColors.Warning else AudioVibeColors.Ink,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 14.sp
|
||||
)
|
||||
MiniPlayerMarqueeText(
|
||||
text = state.artist.ifBlank { strings.unknown },
|
||||
color = AudioVibeColors.Muted,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = onSkipPrevious,
|
||||
modifier = Modifier.size(40.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.SkipPrevious,
|
||||
contentDescription = strings.previousTrack,
|
||||
tint = AudioVibeColors.Ink,
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = onPlayPause,
|
||||
modifier = Modifier.size(44.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = if (showPause) Icons.Default.Pause else Icons.Default.PlayArrow,
|
||||
contentDescription = if (showPause) strings.pause else strings.play,
|
||||
tint = AudioVibeColors.Primary,
|
||||
modifier = Modifier.size(32.dp)
|
||||
)
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = onSkipNext,
|
||||
modifier = Modifier.size(40.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.SkipNext,
|
||||
contentDescription = strings.nextTrack,
|
||||
tint = AudioVibeColors.Ink,
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(3.dp)
|
||||
.background(AudioVibeColors.Line)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(fraction = animatedProgress)
|
||||
.height(3.dp)
|
||||
.background(
|
||||
if (state.hasError) AudioVibeColors.Warning
|
||||
else AudioVibeColors.Primary
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun MiniPlayerMarqueeText(
|
||||
text: String,
|
||||
color: androidx.compose.ui.graphics.Color,
|
||||
fontSize: androidx.compose.ui.unit.TextUnit,
|
||||
fontWeight: FontWeight = FontWeight.Normal
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
color = color,
|
||||
fontWeight = fontWeight,
|
||||
fontSize = fontSize,
|
||||
maxLines = 1,
|
||||
softWrap = false,
|
||||
overflow = TextOverflow.Clip,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.basicMarquee(
|
||||
iterations = Int.MAX_VALUE,
|
||||
repeatDelayMillis = 1200,
|
||||
initialDelayMillis = 700
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.audio.vibe.ui.player
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.audio.vibe.data.playback.PlaybackState
|
||||
|
||||
@Immutable
|
||||
data class MiniPlayerState(
|
||||
val currentId: Long? = null,
|
||||
val title: String = "",
|
||||
val artist: String = "",
|
||||
val isPlaying: Boolean = false,
|
||||
val progressFraction: Float = 0f,
|
||||
val errorMessage: String? = null
|
||||
) {
|
||||
val hasError: Boolean
|
||||
get() = !errorMessage.isNullOrBlank()
|
||||
|
||||
val isVisible: Boolean
|
||||
get() = currentId != null
|
||||
|
||||
companion object {
|
||||
val Hidden = MiniPlayerState()
|
||||
|
||||
fun from(state: PlaybackState): MiniPlayerState {
|
||||
val track = state.currentTrack
|
||||
return MiniPlayerState(
|
||||
currentId = state.currentId,
|
||||
title = track?.title ?: state.currentTitle.orEmpty(),
|
||||
artist = track?.artist ?: state.currentArtist.orEmpty(),
|
||||
isPlaying = state.isPlaying,
|
||||
progressFraction = if (state.durationMs != null && state.durationMs > 0) {
|
||||
(state.progressMs.toFloat() / state.durationMs).coerceIn(0f, 1f)
|
||||
} else 0f,
|
||||
errorMessage = state.errorMessage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
161
app/src/main/java/com/audio/vibe/ui/player/PlayerBottomSheet.kt
Normal file
161
app/src/main/java/com/audio/vibe/ui/player/PlayerBottomSheet.kt
Normal file
@ -0,0 +1,161 @@
|
||||
package com.audio.vibe.ui.player
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.audio.vibe.data.playback.PlaybackAudioParameters
|
||||
import com.audio.vibe.data.playback.PlaybackBackend
|
||||
import com.audio.vibe.ui.components.AudioVibeColors
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PlayerBottomSheet(
|
||||
state: PlayerUiState,
|
||||
onDismiss: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = onDismiss,
|
||||
sheetState = sheetState,
|
||||
containerColor = PlayerSheetColors.Surface,
|
||||
contentColor = Color.White,
|
||||
shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp),
|
||||
dragHandle = { SheetHandle() },
|
||||
modifier = modifier
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp, vertical = 8.dp)
|
||||
.padding(bottom = 32.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
Text(
|
||||
"播放信息",
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 18.sp,
|
||||
color = Color.White,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
|
||||
DecodeSection(state.backend)
|
||||
|
||||
HorizontalDivider(color = PlayerSheetColors.Divider)
|
||||
|
||||
ParameterSection("源参数", state.sourceParameters)
|
||||
|
||||
HorizontalDivider(color = PlayerSheetColors.Divider)
|
||||
|
||||
ParameterSection("输出参数", state.outputParameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SheetHandle() {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(top = 10.dp, bottom = 8.dp)
|
||||
.width(36.dp)
|
||||
.height(4.dp)
|
||||
.clip(RoundedCornerShape(999.dp))
|
||||
.background(PlayerSheetColors.Handle)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DecodeSection(backend: PlaybackBackend?) {
|
||||
val (label, color) = when (backend) {
|
||||
PlaybackBackend.Media3 -> "系统解码" to AudioVibeColors.Success
|
||||
PlaybackBackend.FfmpegAudioTrack -> "软件解码" to AudioVibeColors.Warning
|
||||
null -> return
|
||||
}
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text("解码方式", fontSize = 14.sp, color = PlayerSheetColors.Muted)
|
||||
Spacer(Modifier.width(16.dp))
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(999.dp))
|
||||
.background(color.copy(alpha = 0.15f))
|
||||
.padding(horizontal = 12.dp, vertical = 6.dp)
|
||||
) {
|
||||
Text(
|
||||
label,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = color
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ParameterSection(title: String, params: PlaybackAudioParameters?) {
|
||||
val labels = params?.chipLabels().orEmpty()
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(title, fontSize = 14.sp, color = PlayerSheetColors.Muted)
|
||||
|
||||
if (labels.isEmpty()) {
|
||||
Text("—", fontSize = 13.sp, color = PlayerSheetColors.Muted)
|
||||
} else {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||
labels.forEach { ParamChip(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun PlaybackAudioParameters.chipLabels(): List<String> {
|
||||
return listOfNotNull(
|
||||
format?.takeIf { it.isNotBlank() },
|
||||
sampleRateHz?.takeIf { it > 0 }?.let { "${it / 1000}kHz" },
|
||||
bitDepth?.takeIf { it.isNotBlank() },
|
||||
channelCount?.let { count ->
|
||||
when (count) {
|
||||
1 -> "单声道"
|
||||
2 -> "立体声"
|
||||
else -> "${count}声道"
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ParamChip(label: String) {
|
||||
Text(
|
||||
text = label,
|
||||
fontSize = 13.sp,
|
||||
color = Color.White.copy(alpha = 0.86f)
|
||||
)
|
||||
}
|
||||
|
||||
private object PlayerSheetColors {
|
||||
val Surface = Color(0xFF1D1D1F)
|
||||
val Divider = Color.White.copy(alpha = 0.10f)
|
||||
val Handle = Color.White.copy(alpha = 0.28f)
|
||||
val Muted = Color.White.copy(alpha = 0.52f)
|
||||
}
|
||||
193
app/src/main/java/com/audio/vibe/ui/player/PlayerQueueSheet.kt
Normal file
193
app/src/main/java/com/audio/vibe/ui/player/PlayerQueueSheet.kt
Normal file
@ -0,0 +1,193 @@
|
||||
package com.audio.vibe.ui.player
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.MusicNote
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PlayerQueueSheet(
|
||||
state: PlayerUiState,
|
||||
onTrackClick: (Int) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
val currentIndex = state.queueIndex ?: -1
|
||||
val listState = rememberLazyListState()
|
||||
var didInitialScroll by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(currentIndex, state.queueItems.size, didInitialScroll) {
|
||||
if (!didInitialScroll && currentIndex in state.queueItems.indices) {
|
||||
listState.scrollToItem(currentIndex)
|
||||
didInitialScroll = true
|
||||
}
|
||||
}
|
||||
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = onDismiss,
|
||||
sheetState = sheetState,
|
||||
containerColor = QueueSheetColors.Surface,
|
||||
contentColor = Color.White,
|
||||
shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp),
|
||||
dragHandle = { QueueSheetHandle() },
|
||||
modifier = modifier
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 20.dp)
|
||||
.padding(bottom = 30.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "当前列表",
|
||||
color = Color.White,
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
LazyColumn(
|
||||
state = listState,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = 420.dp)
|
||||
) {
|
||||
itemsIndexed(state.queueItems, key = { index, item -> "${index}-${item.id}" }) { index, item ->
|
||||
QueueTrackRow(
|
||||
index = index,
|
||||
title = item.title.ifBlank { "未知歌曲" },
|
||||
artist = item.artist.ifBlank { "未知艺术家" },
|
||||
selected = index == currentIndex,
|
||||
onClick = { onTrackClick(index) }
|
||||
)
|
||||
if (index < state.queueItems.lastIndex) {
|
||||
HorizontalDivider(color = QueueSheetColors.Divider)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun QueueTrackRow(
|
||||
index: Int,
|
||||
title: String,
|
||||
artist: String,
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(if (selected) QueueSheetColors.Selected else Color.Transparent)
|
||||
.clickable(onClick = onClick)
|
||||
.padding(horizontal = 12.dp, vertical = 11.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(32.dp)
|
||||
.clip(CircleShape)
|
||||
.background(if (selected) QueueSheetColors.Action else QueueSheetColors.IconChrome),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
if (selected) {
|
||||
Icon(
|
||||
Icons.Default.MusicNote,
|
||||
contentDescription = null,
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(18.dp)
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = (index + 1).toString(),
|
||||
color = QueueSheetColors.Muted,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(Modifier.size(12.dp))
|
||||
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = title,
|
||||
color = if (selected) Color.White else QueueSheetColors.PrimaryText,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = if (selected) FontWeight.Bold else FontWeight.SemiBold,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
text = artist,
|
||||
color = if (selected) QueueSheetColors.Action else QueueSheetColors.Muted,
|
||||
fontSize = 12.sp,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun QueueSheetHandle() {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(top = 10.dp, bottom = 8.dp)
|
||||
.fillMaxWidth(0.1f)
|
||||
.height(4.dp)
|
||||
.clip(RoundedCornerShape(999.dp))
|
||||
.background(QueueSheetColors.Handle)
|
||||
)
|
||||
}
|
||||
|
||||
private object QueueSheetColors {
|
||||
val Surface = Color(0xFF1D1D1F)
|
||||
val Selected = Color(0x1F2997FF)
|
||||
val Action = Color(0xFF2997FF)
|
||||
val PrimaryText = Color.White.copy(alpha = 0.88f)
|
||||
val Muted = Color.White.copy(alpha = 0.52f)
|
||||
val Divider = Color.White.copy(alpha = 0.08f)
|
||||
val Handle = Color.White.copy(alpha = 0.28f)
|
||||
val IconChrome = Color.White.copy(alpha = 0.10f)
|
||||
}
|
||||
791
app/src/main/java/com/audio/vibe/ui/player/PlayerScreen.kt
Normal file
791
app/src/main/java/com/audio/vibe/ui/player/PlayerScreen.kt
Normal file
@ -0,0 +1,791 @@
|
||||
package com.audio.vibe.ui.player
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.basicMarquee
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Pause
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.SkipNext
|
||||
import androidx.compose.material.icons.filled.SkipPrevious
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.SliderDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.audio.vibe.R
|
||||
import com.audio.vibe.data.playback.AudioPlaybackService
|
||||
import com.audio.vibe.data.playback.PlaybackServiceController
|
||||
import com.audio.vibe.domain.model.PlayMode
|
||||
import com.audio.vibe.ui.components.AudioVibeColors
|
||||
import kotlin.math.abs
|
||||
|
||||
@Composable
|
||||
fun PlayerScreen(onBack: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
var controller by remember { mutableStateOf<PlaybackServiceController?>(null) }
|
||||
PlayerSystemBars()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
controller = AudioPlaybackService.startAndBindController(context.applicationContext)
|
||||
}
|
||||
|
||||
if (controller == null) return
|
||||
|
||||
PlayerContent(
|
||||
onBack = onBack,
|
||||
controller = controller!!
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PlayerContent(
|
||||
onBack: () -> Unit,
|
||||
controller: PlaybackServiceController
|
||||
) {
|
||||
val viewModel: PlayerViewModel = viewModel(
|
||||
factory = PlayerViewModelFactory(controller)
|
||||
)
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
var scrubStartedButtonState by remember { mutableStateOf<Boolean?>(null) }
|
||||
var heldSeekButtonState by remember { mutableStateOf<Boolean?>(null) }
|
||||
var heldSeekTargetMs by remember { mutableStateOf<Long?>(null) }
|
||||
var heldSeekTrackId by remember { mutableStateOf<Long?>(null) }
|
||||
val trackText = rememberStableTrackText(
|
||||
currentId = uiState.currentId,
|
||||
title = uiState.title,
|
||||
artist = uiState.artist,
|
||||
album = uiState.album
|
||||
)
|
||||
val context = LocalContext.current
|
||||
|
||||
LaunchedEffect(uiState.errorMessage) {
|
||||
uiState.errorMessage?.takeIf { it.isNotBlank() }?.let { message ->
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(uiState.currentId, uiState.progressMs, uiState.isPlaying, heldSeekTargetMs) {
|
||||
val target = heldSeekTargetMs ?: return@LaunchedEffect
|
||||
val expectedButtonState = heldSeekButtonState ?: return@LaunchedEffect
|
||||
if (uiState.currentId != heldSeekTrackId) {
|
||||
heldSeekButtonState = null
|
||||
heldSeekTargetMs = null
|
||||
heldSeekTrackId = null
|
||||
return@LaunchedEffect
|
||||
}
|
||||
if (uiState.isPlaying == expectedButtonState && abs(uiState.progressMs - target) < 750L) {
|
||||
heldSeekButtonState = null
|
||||
heldSeekTargetMs = null
|
||||
heldSeekTrackId = null
|
||||
}
|
||||
}
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
PlayerBackdrop(
|
||||
sourcePath = uiState.sourcePath,
|
||||
uri = uiState.uri,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.statusBarsPadding()
|
||||
.navigationBarsPadding()
|
||||
.padding(horizontal = 24.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
PlayerTopBar(
|
||||
onBack = onBack,
|
||||
onQueueClick = viewModel::onToggleQueueSheet
|
||||
)
|
||||
|
||||
Spacer(Modifier.weight(1f))
|
||||
|
||||
CoverImage(
|
||||
sourcePath = uiState.sourcePath,
|
||||
uri = uiState.uri,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(0.82f)
|
||||
.widthIn(max = 320.dp)
|
||||
.aspectRatio(1f)
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(30.dp))
|
||||
|
||||
TrackInfoText(
|
||||
text = trackText
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(32.dp))
|
||||
|
||||
ProgressSection(
|
||||
positionMs = uiState.progressMs,
|
||||
durationMs = uiState.durationMs,
|
||||
canSeek = uiState.canSeek,
|
||||
onScrubStart = {
|
||||
scrubStartedButtonState = heldSeekButtonState ?: uiState.isPlaying
|
||||
},
|
||||
onSeekTo = { target ->
|
||||
heldSeekButtonState = scrubStartedButtonState ?: uiState.isPlaying
|
||||
heldSeekTargetMs = target
|
||||
heldSeekTrackId = uiState.currentId
|
||||
scrubStartedButtonState = null
|
||||
viewModel.onSeekTo(target)
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(18.dp))
|
||||
|
||||
PlayControlRow(
|
||||
showPause = heldSeekButtonState ?: uiState.isPlaying,
|
||||
onSkipPrevious = viewModel::onSkipPrevious,
|
||||
onPlayPause = {
|
||||
heldSeekButtonState = null
|
||||
heldSeekTargetMs = null
|
||||
heldSeekTrackId = null
|
||||
viewModel.onPlayPause()
|
||||
},
|
||||
onSkipNext = viewModel::onSkipNext
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(18.dp))
|
||||
|
||||
PlaybackMetaRow(
|
||||
queueLabel = uiState.queueLabel,
|
||||
playMode = uiState.playMode,
|
||||
onTogglePlayMode = viewModel::onTogglePlayMode
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(18.dp))
|
||||
|
||||
AudioChainInfoBar(
|
||||
decodeLabel = uiState.decodeLabel,
|
||||
audioChain = uiState.audioChain,
|
||||
onClick = viewModel::onToggleBottomSheet
|
||||
)
|
||||
|
||||
Spacer(Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
|
||||
if (uiState.showBottomSheet) {
|
||||
PlayerBottomSheet(
|
||||
state = uiState,
|
||||
onDismiss = viewModel::onDismissBottomSheet
|
||||
)
|
||||
}
|
||||
|
||||
if (uiState.showQueueSheet) {
|
||||
PlayerQueueSheet(
|
||||
state = uiState,
|
||||
onTrackClick = viewModel::onPlayQueueItem,
|
||||
onDismiss = viewModel::onDismissQueueSheet
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private data class StableTrackText(
|
||||
val title: String,
|
||||
val subtitle: String
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun rememberStableTrackText(
|
||||
currentId: Long?,
|
||||
title: String,
|
||||
artist: String,
|
||||
album: String
|
||||
): StableTrackText {
|
||||
var displayedText by remember {
|
||||
mutableStateOf(
|
||||
StableTrackText(
|
||||
title = title,
|
||||
subtitle = trackSubtitleOrBlank(artist, album)
|
||||
)
|
||||
)
|
||||
}
|
||||
var displayedTrackId by remember { mutableStateOf(currentId) }
|
||||
|
||||
LaunchedEffect(currentId, title, artist, album) {
|
||||
if (currentId == null) return@LaunchedEffect
|
||||
val nextTitle = title.trim()
|
||||
val nextSubtitle = trackSubtitleOrBlank(artist, album)
|
||||
if (currentId != displayedTrackId && nextTitle.isBlank() && nextSubtitle.isBlank()) {
|
||||
return@LaunchedEffect
|
||||
}
|
||||
|
||||
displayedText = StableTrackText(
|
||||
title = nextTitle,
|
||||
subtitle = nextSubtitle
|
||||
)
|
||||
displayedTrackId = currentId
|
||||
}
|
||||
|
||||
return displayedText
|
||||
}
|
||||
|
||||
private fun trackSubtitleOrBlank(
|
||||
artist: String,
|
||||
album: String
|
||||
): String {
|
||||
return listOfNotNull(
|
||||
artist.ifBlank { null },
|
||||
album.ifBlank { null }
|
||||
).joinToString(" · ")
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TrackInfoText(
|
||||
text: StableTrackText
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(57.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
MarqueeText(
|
||||
text = text.title.ifBlank { TrackTextPlaceholder },
|
||||
color = if (text.title.isBlank()) Color.Transparent else Color.White,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontSize = 24.sp,
|
||||
lineHeight = 29.sp,
|
||||
height = 31.dp
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(4.dp))
|
||||
|
||||
MarqueeText(
|
||||
text = text.subtitle.ifBlank { TrackTextPlaceholder },
|
||||
color = if (text.subtitle.isBlank()) Color.Transparent else PlayerColors.secondaryText,
|
||||
fontSize = 15.sp,
|
||||
lineHeight = 20.sp,
|
||||
height = 22.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private const val TrackTextPlaceholder = " "
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun MarqueeText(
|
||||
text: String,
|
||||
color: Color,
|
||||
fontSize: androidx.compose.ui.unit.TextUnit,
|
||||
lineHeight: androidx.compose.ui.unit.TextUnit,
|
||||
height: androidx.compose.ui.unit.Dp,
|
||||
modifier: Modifier = Modifier,
|
||||
fontWeight: FontWeight = FontWeight.Normal
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.height(height),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
color = color,
|
||||
fontWeight = fontWeight,
|
||||
fontSize = fontSize,
|
||||
lineHeight = lineHeight,
|
||||
maxLines = 1,
|
||||
softWrap = false,
|
||||
overflow = TextOverflow.Clip,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.basicMarquee(
|
||||
iterations = Int.MAX_VALUE,
|
||||
repeatDelayMillis = 1200,
|
||||
initialDelayMillis = 700
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PlayerBackdrop(
|
||||
sourcePath: String?,
|
||||
uri: android.net.Uri?,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Box(modifier = modifier) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(
|
||||
Brush.linearGradient(
|
||||
colors = listOf(
|
||||
PlayerColors.canvasTop,
|
||||
PlayerColors.canvas,
|
||||
Color.Black
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.blur(64.dp)
|
||||
) {
|
||||
CoverImage(
|
||||
sourcePath = sourcePath,
|
||||
uri = uri,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
cornerRadius = 0.dp
|
||||
)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black.copy(alpha = 0.72f))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PlayerTopBar(
|
||||
onBack: () -> Unit,
|
||||
onQueueClick: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(58.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onBack,
|
||||
modifier = Modifier
|
||||
.size(42.dp)
|
||||
.clip(CircleShape)
|
||||
.background(PlayerColors.chrome)
|
||||
) {
|
||||
Icon(
|
||||
Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = "返回",
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(22.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.weight(1f))
|
||||
IconButton(
|
||||
onClick = onQueueClick,
|
||||
modifier = Modifier.size(42.dp)
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.drawable.img_current_queue),
|
||||
contentDescription = "当前列表",
|
||||
modifier = Modifier
|
||||
.size(42.dp)
|
||||
.clip(CircleShape)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ProgressSection(
|
||||
positionMs: Long,
|
||||
durationMs: Long?,
|
||||
canSeek: Boolean,
|
||||
onScrubStart: () -> Unit,
|
||||
onSeekTo: (Long) -> Unit
|
||||
) {
|
||||
val duration = durationMs?.takeIf { it > 0 } ?: return
|
||||
var scrubPosition by remember { mutableFloatStateOf(positionMs.toFloat()) }
|
||||
var isScrubbing by remember { mutableStateOf(false) }
|
||||
val durationFloat = duration.toFloat().takeIf { it.isUsableSliderValue() } ?: return
|
||||
|
||||
LaunchedEffect(positionMs, isScrubbing) {
|
||||
if (!isScrubbing) {
|
||||
scrubPosition = positionMs.toFloat()
|
||||
}
|
||||
}
|
||||
|
||||
val displayedPosition = scrubPosition.boundSliderValue(durationFloat)
|
||||
val progressFraction = (displayedPosition / durationFloat).coerceIn(0f, 1f)
|
||||
val activeWeight = progressFraction.coerceAtLeast(0.001f)
|
||||
val inactiveWeight = (1f - progressFraction).coerceAtLeast(0.001f)
|
||||
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(36.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.Center)
|
||||
.fillMaxWidth()
|
||||
.height(4.dp)
|
||||
.clip(RoundedCornerShape(999.dp))
|
||||
.background(PlayerColors.track)
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.align(Alignment.Center)
|
||||
.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(activeWeight)
|
||||
.height(4.dp)
|
||||
.clip(RoundedCornerShape(999.dp))
|
||||
.background(
|
||||
if (canSeek) PlayerColors.action else PlayerColors.action.copy(
|
||||
alpha = 0.45f
|
||||
)
|
||||
)
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(if (isScrubbing) 14.dp else 11.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Color.White)
|
||||
)
|
||||
Spacer(Modifier.weight(inactiveWeight))
|
||||
}
|
||||
|
||||
Slider(
|
||||
value = displayedPosition,
|
||||
onValueChange = {
|
||||
if (!isScrubbing) {
|
||||
onScrubStart()
|
||||
}
|
||||
isScrubbing = true
|
||||
scrubPosition = it.boundSliderValue(durationFloat)
|
||||
},
|
||||
onValueChangeFinished = {
|
||||
val target = scrubPosition.boundSliderValue(durationFloat).toLong()
|
||||
.coerceIn(0L, duration)
|
||||
scrubPosition = target.toFloat()
|
||||
isScrubbing = false
|
||||
onSeekTo(target)
|
||||
},
|
||||
valueRange = 0f..durationFloat,
|
||||
enabled = canSeek,
|
||||
colors = SliderDefaults.colors(
|
||||
thumbColor = Color.Transparent,
|
||||
activeTrackColor = Color.Transparent,
|
||||
inactiveTrackColor = Color.Transparent,
|
||||
disabledThumbColor = Color.Transparent,
|
||||
disabledActiveTrackColor = Color.Transparent,
|
||||
disabledInactiveTrackColor = Color.Transparent
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(36.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = displayedPosition.toLong().formatMs(),
|
||||
color = PlayerColors.tertiaryText,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
Text(
|
||||
text = duration.formatMs(),
|
||||
color = PlayerColors.tertiaryText,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PlayControlRow(
|
||||
showPause: Boolean,
|
||||
onSkipPrevious: () -> Unit,
|
||||
onPlayPause: () -> Unit,
|
||||
onSkipNext: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onSkipPrevious,
|
||||
modifier = Modifier.size(58.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.SkipPrevious,
|
||||
contentDescription = "上一首",
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(34.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.width(24.dp))
|
||||
|
||||
IconButton(
|
||||
onClick = onPlayPause,
|
||||
modifier = Modifier
|
||||
.size(78.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Color.White)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = if (showPause) Icons.Default.Pause else Icons.Default.PlayArrow,
|
||||
contentDescription = if (showPause) "暂停" else "播放",
|
||||
tint = PlayerColors.canvas,
|
||||
modifier = Modifier.size(48.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.width(24.dp))
|
||||
|
||||
IconButton(
|
||||
onClick = onSkipNext,
|
||||
modifier = Modifier.size(58.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.SkipNext,
|
||||
contentDescription = "下一首",
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(34.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PlaybackMetaRow(
|
||||
queueLabel: String,
|
||||
playMode: PlayMode,
|
||||
onTogglePlayMode: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = 38.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
ModeChip(
|
||||
playMode = playMode,
|
||||
onClick = onTogglePlayMode
|
||||
)
|
||||
|
||||
Spacer(Modifier.width(12.dp))
|
||||
|
||||
Text(
|
||||
text = queueLabel,
|
||||
color = PlayerColors.tertiaryText,
|
||||
fontSize = 13.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ModeChip(
|
||||
playMode: PlayMode,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(999.dp))
|
||||
.background(PlayerColors.modeChrome)
|
||||
.clickable(onClick = onClick)
|
||||
.padding(horizontal = 13.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
PlayModeIcon(playMode)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(
|
||||
text = playMode.label(),
|
||||
color = Color.White,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PlayModeIcon(playMode: PlayMode) {
|
||||
Icon(
|
||||
painter = painterResource(playMode.iconRes()),
|
||||
contentDescription = playMode.label(),
|
||||
tint = Color.Unspecified,
|
||||
modifier = Modifier.size(22.dp)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AudioChainInfoBar(
|
||||
decodeLabel: String,
|
||||
audioChain: String,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
val decodeColor = when (decodeLabel) {
|
||||
"系统解码" -> AudioVibeColors.Success
|
||||
"软件解码" -> AudioVibeColors.Warning
|
||||
else -> AudioVibeColors.Muted
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(PlayerColors.chrome)
|
||||
.clickable(onClick = onClick)
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (decodeLabel.isNotBlank()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(999.dp))
|
||||
.background(decodeColor.copy(alpha = 0.18f))
|
||||
.padding(horizontal = 9.dp, vertical = 5.dp)
|
||||
) {
|
||||
Text(
|
||||
decodeLabel,
|
||||
fontSize = 11.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = decodeColor
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(10.dp))
|
||||
}
|
||||
|
||||
Text(
|
||||
text = audioChain.ifBlank { "—" },
|
||||
color = PlayerColors.secondaryText,
|
||||
fontSize = 12.sp,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(end = 4.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "▼",
|
||||
color = PlayerColors.tertiaryText,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private object PlayerColors {
|
||||
val canvas = Color(0xFF050506)
|
||||
val canvasTop = Color(0xFF1D1D1F)
|
||||
val chrome = Color.White.copy(alpha = 0.10f)
|
||||
val modeChrome = Color.White.copy(alpha = 0.08f)
|
||||
val action = Color(0xFF2997FF)
|
||||
val track = Color.White.copy(alpha = 0.16f)
|
||||
val secondaryText = Color.White.copy(alpha = 0.72f)
|
||||
val tertiaryText = Color.White.copy(alpha = 0.48f)
|
||||
val disabled = Color.White.copy(alpha = 0.25f)
|
||||
}
|
||||
|
||||
private fun PlayMode.label(): String = when (this) {
|
||||
PlayMode.ListCycle -> "循环"
|
||||
PlayMode.ListOnce -> "顺序"
|
||||
PlayMode.RepeatOne -> "单曲"
|
||||
PlayMode.Shuffle -> "随机"
|
||||
}
|
||||
|
||||
private fun PlayMode.iconRes(): Int = when (this) {
|
||||
PlayMode.ListCycle -> R.drawable.img_play_mode_cycle
|
||||
PlayMode.ListOnce -> R.drawable.img_play_mode_once
|
||||
PlayMode.RepeatOne -> R.drawable.img_play_mode_repeat_one
|
||||
PlayMode.Shuffle -> R.drawable.img_play_mode_shuffle
|
||||
}
|
||||
|
||||
private fun Long.formatMs(): String {
|
||||
val totalSec = (this / 1000).coerceAtLeast(0)
|
||||
return "${totalSec / 60}:${(totalSec % 60).toString().padStart(2, '0')}"
|
||||
}
|
||||
|
||||
private fun Float.boundSliderValue(max: Float): Float {
|
||||
if (!isUsableSliderValue()) return 0f
|
||||
return coerceIn(0f, max)
|
||||
}
|
||||
|
||||
private fun Float.isUsableSliderValue(): Boolean {
|
||||
return !isNaN() && !isInfinite() && this > 0f
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PlayerSystemBars() {
|
||||
val view = LocalView.current
|
||||
DisposableEffect(view) {
|
||||
val window = view.context.findActivity()?.window
|
||||
val controller = window?.let { WindowCompat.getInsetsController(it, view) }
|
||||
controller?.isAppearanceLightStatusBars = false
|
||||
|
||||
onDispose {
|
||||
controller?.isAppearanceLightStatusBars = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private tailrec fun Context.findActivity(): Activity? = when (this) {
|
||||
is Activity -> this
|
||||
is ContextWrapper -> baseContext.findActivity()
|
||||
else -> null
|
||||
}
|
||||
62
app/src/main/java/com/audio/vibe/ui/player/PlayerUiState.kt
Normal file
62
app/src/main/java/com/audio/vibe/ui/player/PlayerUiState.kt
Normal file
@ -0,0 +1,62 @@
|
||||
package com.audio.vibe.ui.player
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.audio.vibe.data.playback.PlaybackAudioParameters
|
||||
import com.audio.vibe.data.playback.PlaybackBackend
|
||||
import com.audio.vibe.data.playback.PlaybackQueueItem
|
||||
import com.audio.vibe.domain.model.PlayMode
|
||||
|
||||
@Immutable
|
||||
data class PlayerUiState(
|
||||
val currentId: Long? = null,
|
||||
val title: String = "",
|
||||
val artist: String = "",
|
||||
val album: String = "",
|
||||
val isPlaying: Boolean = false,
|
||||
val positionMs: Long = 0L,
|
||||
val progressMs: Long = 0L,
|
||||
val durationMs: Long? = null,
|
||||
val canSeek: Boolean = false,
|
||||
val canPrevious: Boolean = false,
|
||||
val canNext: Boolean = false,
|
||||
val queueItems: List<PlaybackQueueItem> = emptyList(),
|
||||
val queueIndex: Int? = null,
|
||||
val queueSize: Int = 0,
|
||||
val playMode: PlayMode = PlayMode.default,
|
||||
val backend: PlaybackBackend? = null,
|
||||
val sourceParameters: PlaybackAudioParameters? = null,
|
||||
val outputParameters: PlaybackAudioParameters? = null,
|
||||
val errorMessage: String? = null,
|
||||
val sourcePath: String? = null,
|
||||
val uri: android.net.Uri? = null,
|
||||
val showBottomSheet: Boolean = false,
|
||||
val showQueueSheet: Boolean = false
|
||||
) {
|
||||
val hasError: Boolean
|
||||
get() = !errorMessage.isNullOrBlank()
|
||||
|
||||
val queueLabel: String
|
||||
get() = if (queueSize > 0) "${(queueIndex ?: 0) + 1} / $queueSize" else "-"
|
||||
|
||||
val decodeLabel: String
|
||||
get() = when (backend) {
|
||||
PlaybackBackend.Media3 -> "系统解码"
|
||||
PlaybackBackend.FfmpegAudioTrack -> "软件解码"
|
||||
null -> ""
|
||||
}
|
||||
|
||||
val audioChain: String
|
||||
get() {
|
||||
val srcPart = sourceParameters?.summaryLabel().orEmpty()
|
||||
val outPart = outputParameters?.summaryLabel().orEmpty()
|
||||
return if (outPart.isNotBlank()) "$srcPart → $outPart" else srcPart
|
||||
}
|
||||
}
|
||||
|
||||
internal fun PlaybackAudioParameters.summaryLabel(): String {
|
||||
return listOfNotNull(
|
||||
format?.takeIf { it.isNotBlank() },
|
||||
sampleRateHz?.takeIf { it > 0 }?.let { "${it / 1000}kHz" },
|
||||
bitDepth?.takeIf { it.isNotBlank() }
|
||||
).joinToString(" ")
|
||||
}
|
||||
111
app/src/main/java/com/audio/vibe/ui/player/PlayerViewModel.kt
Normal file
111
app/src/main/java/com/audio/vibe/ui/player/PlayerViewModel.kt
Normal file
@ -0,0 +1,111 @@
|
||||
package com.audio.vibe.ui.player
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.audio.vibe.data.playback.PlaybackServiceController
|
||||
import com.audio.vibe.data.playback.PlaybackState
|
||||
import com.audio.vibe.domain.model.PlayMode
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class PlayerViewModel(
|
||||
private val controller: PlaybackServiceController
|
||||
) : ViewModel() {
|
||||
|
||||
private val _uiState = MutableStateFlow(PlayerUiState())
|
||||
val uiState: StateFlow<PlayerUiState> = _uiState
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
controller.state.collect { playbackState ->
|
||||
_uiState.update { it.fromPlaybackState(playbackState) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onPlayPause() {
|
||||
controller.toggleCurrent()
|
||||
}
|
||||
|
||||
fun onSkipNext() {
|
||||
controller.playNext()
|
||||
}
|
||||
|
||||
fun onSkipPrevious() {
|
||||
controller.playPrevious()
|
||||
}
|
||||
|
||||
fun onPlayQueueItem(index: Int) {
|
||||
if (controller.playQueueIndex(index)) {
|
||||
_uiState.update { it.copy(showQueueSheet = false) }
|
||||
}
|
||||
}
|
||||
|
||||
fun onSeekTo(positionMs: Long) {
|
||||
controller.seekTo(positionMs)
|
||||
}
|
||||
|
||||
fun onTogglePlayMode() {
|
||||
val newMode = _uiState.value.playMode.next()
|
||||
_uiState.update { it.copy(playMode = newMode) }
|
||||
controller.setPlayMode(newMode)
|
||||
}
|
||||
|
||||
fun onToggleBottomSheet() {
|
||||
_uiState.update { it.copy(showBottomSheet = !it.showBottomSheet) }
|
||||
}
|
||||
|
||||
fun onDismissBottomSheet() {
|
||||
_uiState.update { it.copy(showBottomSheet = false) }
|
||||
}
|
||||
|
||||
fun onToggleQueueSheet() {
|
||||
_uiState.update { it.copy(showQueueSheet = !it.showQueueSheet) }
|
||||
}
|
||||
|
||||
fun onDismissQueueSheet() {
|
||||
_uiState.update { it.copy(showQueueSheet = false) }
|
||||
}
|
||||
}
|
||||
|
||||
class PlayerViewModelFactory(
|
||||
private val controller: PlaybackServiceController
|
||||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(PlayerViewModel::class.java)) {
|
||||
return PlayerViewModel(controller) as T
|
||||
}
|
||||
throw IllegalArgumentException("Unknown ViewModel class: ${modelClass.name}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun PlayerUiState.fromPlaybackState(state: PlaybackState): PlayerUiState {
|
||||
val hasCurrentTrack = state.currentId != null || state.currentTrack != null
|
||||
return copy(
|
||||
currentId = state.currentId,
|
||||
title = state.currentTitle.orEmpty().ifBlank { state.currentTrack?.title.orEmpty() },
|
||||
artist = state.currentArtist.orEmpty().ifBlank { state.currentTrack?.artist.orEmpty() },
|
||||
album = state.currentTrack?.album.orEmpty(),
|
||||
isPlaying = state.isPlaying,
|
||||
positionMs = state.positionMs,
|
||||
progressMs = state.progressMs,
|
||||
durationMs = state.durationMs,
|
||||
canSeek = state.canSeek,
|
||||
canPrevious = state.canPrevious,
|
||||
canNext = state.canNext,
|
||||
queueItems = state.queueItems,
|
||||
queueIndex = state.queueIndex,
|
||||
queueSize = state.queueSize,
|
||||
playMode = state.playMode,
|
||||
backend = if (hasCurrentTrack) state.backend ?: backend else null,
|
||||
sourceParameters = if (hasCurrentTrack) state.sourceParameters ?: sourceParameters else null,
|
||||
outputParameters = if (hasCurrentTrack) state.outputParameters ?: outputParameters else null,
|
||||
errorMessage = state.errorMessage,
|
||||
sourcePath = state.currentTrack?.sourcePath,
|
||||
uri = state.currentTrack?.uri
|
||||
)
|
||||
}
|
||||
@ -69,15 +69,31 @@ fun SettingsScreen(
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(bottom = 16.dp),
|
||||
.padding(start = 20.dp, end = 20.dp, bottom = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
VibeCard(modifier = Modifier.fillMaxWidth().height(112.dp), onClick = toPremium) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize()) {
|
||||
VibeCard(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(112.dp), onClick = toPremium) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
RoundIcon(Icons.Default.Shield, strings.premium)
|
||||
Column(Modifier.padding(start = 16.dp).weight(1f)) {
|
||||
Text(strings.upgradePremium, color = AudioVibeColors.Ink, fontWeight = FontWeight.Bold, fontSize = 18.sp)
|
||||
Text(strings.removeAdsCloudVoices, color = AudioVibeColors.Muted, fontSize = 12.sp)
|
||||
Column(Modifier
|
||||
.padding(start = 16.dp)
|
||||
.weight(1f)) {
|
||||
Text(
|
||||
strings.upgradePremium,
|
||||
color = AudioVibeColors.Ink,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 18.sp
|
||||
)
|
||||
Text(
|
||||
strings.removeAdsCloudVoices,
|
||||
color = AudioVibeColors.Muted,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
}
|
||||
PrimaryButton(strings.view, onClick = toPremium)
|
||||
}
|
||||
@ -92,8 +108,21 @@ fun SettingsScreen(
|
||||
.padding(horizontal = 2.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
RoundIcon(item.icon, item.label, size = 34.dp, tint = AudioVibeColors.Muted, background = AudioVibeColors.Background)
|
||||
Text(item.label, color = AudioVibeColors.Ink, fontWeight = FontWeight.Medium, modifier = Modifier.padding(start = 14.dp).weight(1f))
|
||||
RoundIcon(
|
||||
item.icon,
|
||||
item.label,
|
||||
size = 34.dp,
|
||||
tint = AudioVibeColors.Muted,
|
||||
background = AudioVibeColors.Background
|
||||
)
|
||||
Text(
|
||||
item.label,
|
||||
color = AudioVibeColors.Ink,
|
||||
fontWeight = FontWeight.Medium,
|
||||
modifier = Modifier
|
||||
.padding(start = 14.dp)
|
||||
.weight(1f)
|
||||
)
|
||||
Text(
|
||||
when (item.label) {
|
||||
strings.theme -> strings.themeSystem
|
||||
@ -103,12 +132,21 @@ fun SettingsScreen(
|
||||
color = AudioVibeColors.Muted,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
androidx.compose.material3.IconButton(onClick = { dialog = item.label }) {
|
||||
androidx.compose.material3.Icon(Icons.Default.ChevronRight, null, tint = AudioVibeColors.Muted)
|
||||
androidx.compose.material3.IconButton(onClick = {
|
||||
dialog = item.label
|
||||
}) {
|
||||
androidx.compose.material3.Icon(
|
||||
Icons.Default.ChevronRight,
|
||||
null,
|
||||
tint = AudioVibeColors.Muted
|
||||
)
|
||||
}
|
||||
}
|
||||
if (index != items.lastIndex) {
|
||||
Spacer(Modifier.height(1.dp).fillMaxWidth().padding(start = 48.dp))
|
||||
Spacer(Modifier
|
||||
.height(1.dp)
|
||||
.fillMaxWidth()
|
||||
.padding(start = 48.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
app/src/main/res/drawable-nodpi/img_current_queue.png
Normal file
BIN
app/src/main/res/drawable-nodpi/img_current_queue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 708 KiB |
BIN
app/src/main/res/drawable-nodpi/img_play_mode_cycle.png
Normal file
BIN
app/src/main/res/drawable-nodpi/img_play_mode_cycle.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
BIN
app/src/main/res/drawable-nodpi/img_play_mode_once.png
Normal file
BIN
app/src/main/res/drawable-nodpi/img_play_mode_once.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
BIN
app/src/main/res/drawable-nodpi/img_play_mode_repeat_one.png
Normal file
BIN
app/src/main/res/drawable-nodpi/img_play_mode_repeat_one.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
BIN
app/src/main/res/drawable-nodpi/img_play_mode_shuffle.png
Normal file
BIN
app/src/main/res/drawable-nodpi/img_play_mode_shuffle.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
@ -5,6 +5,6 @@
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#356EF5"
|
||||
android:fillColor="#101827"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
</vector>
|
||||
|
||||
@ -5,36 +5,37 @@
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#173A78"
|
||||
android:pathData="M29,24h50c5.52,0 10,4.48 10,10v40c0,5.52 -4.48,10 -10,10h-50c-5.52,0 -10,-4.48 -10,-10v-40c0,-5.52 4.48,-10 10,-10z" />
|
||||
android:fillColor="#1D263A"
|
||||
android:pathData="M28,20h52c6.63,0 12,5.37 12,12v44c0,6.63 -5.37,12 -12,12h-52c-6.63,0 -12,-5.37 -12,-12v-44c0,-6.63 5.37,-12 12,-12z" />
|
||||
<path
|
||||
android:fillColor="#4D7DFF"
|
||||
android:pathData="M41,34h38c2.76,0 5,2.24 5,5v30c0,2.76 -2.24,5 -5,5h-38c-2.76,0 -5,-2.24 -5,-5v-30c0,-2.76 2.24,-5 5,-5z" />
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M28,20h52c6.63,0 12,5.37 12,12v44c0,6.63 -5.37,12 -12,12h-52c-6.63,0 -12,-5.37 -12,-12v-44c0,-6.63 5.37,-12 12,-12z"
|
||||
android:strokeColor="#2F3B53"
|
||||
android:strokeWidth="1.2" />
|
||||
<path
|
||||
android:fillColor="#DCE8FF"
|
||||
android:pathData="M64,38v23.6c0,5.2 -4.22,9.4 -9.42,9.4c-5.12,0 -9.28,-4.08 -9.28,-9.12c0,-5.1 4.16,-9.22 9.28,-9.22c1.62,0 3.12,0.4 4.42,1.12v-19.78h5z" />
|
||||
<path
|
||||
android:fillColor="#DCE8FF"
|
||||
android:pathData="M64,38l16,4.4v7.1l-16,-4.35z" />
|
||||
android:fillColor="#F5F7FF"
|
||||
android:pathData="M62,31h6.5v31.8c0,7.35 -6.36,13.2 -14.1,13.2c-7.4,0 -13.4,-5.16 -13.4,-11.55c0,-6.43 6,-11.65 13.4,-11.65c2.77,0 5.37,0.72 7.6,2.05z" />
|
||||
<path
|
||||
android:fillColor="#356EF5"
|
||||
android:pathData="M54.58,58.08a3.86,3.86 0,1 0,0 7.72a3.86,3.86 0,1 0,0 -7.72" />
|
||||
android:pathData="M68.5,31l17,4.55v8.5l-17,-4.48z" />
|
||||
<path
|
||||
android:fillColor="#356EF5"
|
||||
android:fillAlpha="0.94"
|
||||
android:pathData="M54.4,56.45a5.1,4.05 0,1 0,0 8.1a5.1,4.05 0,1 0,0 -8.1" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M30,47c2.2,-4.3 5.1,-6.45 8.7,-6.45c5.4,0 5.4,6.45 10.8,6.45c3.6,0 6.5,-2.15 8.7,-6.45"
|
||||
android:strokeColor="#DCE8FF"
|
||||
android:pathData="M27,43c3.1,-5.2 7,-7.8 11.7,-7.8c7.05,0 7.05,7.8 14.1,7.8c4.7,0 8.6,-2.6 11.7,-7.8"
|
||||
android:strokeColor="#356EF5"
|
||||
android:strokeAlpha="0.92"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="4" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M27,55c3.1,-5.2 7,-7.8 11.7,-7.8c7.05,0 7.05,7.8 14.1,7.8c4.7,0 8.6,-2.6 11.7,-7.8"
|
||||
android:strokeColor="#ADB8CC"
|
||||
android:strokeAlpha="0.45"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="3" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M30,61c2.2,-4.3 5.1,-6.45 8.7,-6.45c5.4,0 5.4,6.45 10.8,6.45c3.6,0 6.5,-2.15 8.7,-6.45"
|
||||
android:strokeColor="#BFD4FF"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="3" />
|
||||
<path
|
||||
android:fillColor="#DCE8FF"
|
||||
android:fillAlpha="0.90"
|
||||
android:pathData="M78,24l1.7,4.1l4.3,1.6l-4.3,1.7l-1.7,4.1l-1.6,-4.1l-4.3,-1.7l4.3,-1.6z" />
|
||||
</vector>
|
||||
|
||||
10
app/src/main/res/drawable/ic_notification_next.xml
Normal file
10
app/src/main/res/drawable/ic_notification_next.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M16,5H18V19H16V5ZM6,6L15,12L6,18V6Z" />
|
||||
</vector>
|
||||
10
app/src/main/res/drawable/ic_notification_pause.xml
Normal file
10
app/src/main/res/drawable/ic_notification_pause.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M7,5H10V19H7V5ZM14,5H17V19H14V5Z" />
|
||||
</vector>
|
||||
10
app/src/main/res/drawable/ic_notification_play.xml
Normal file
10
app/src/main/res/drawable/ic_notification_play.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M8,5V19L19,12L8,5Z" />
|
||||
</vector>
|
||||
10
app/src/main/res/drawable/ic_notification_previous.xml
Normal file
10
app/src/main/res/drawable/ic_notification_previous.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6,5H8V19H6V5ZM18,6V18L9,12L18,6Z" />
|
||||
</vector>
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/audio_vibe_launcher_foreground" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/audio_vibe_launcher_foreground" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
||||
@ -100,6 +100,7 @@
|
||||
<string name="scan_again">Scan system library</string>
|
||||
<string name="scan_folder">Scan folder / drive</string>
|
||||
<string name="reset_library">Reset library</string>
|
||||
<string name="loading_library">Loading library...</string>
|
||||
<string name="scanning">Scanning local audio...</string>
|
||||
<string name="scanned_count">%1$d songs scanned</string>
|
||||
<string name="cached_library">Showing saved library while scanning</string>
|
||||
@ -110,4 +111,8 @@
|
||||
<string name="high_res">Hi-res</string>
|
||||
<string name="formats">Formats</string>
|
||||
<string name="unknown">Unknown</string>
|
||||
<string name="play">Play</string>
|
||||
<string name="pause">Pause</string>
|
||||
<string name="next_track">Next</string>
|
||||
<string name="previous_track">Previous</string>
|
||||
</resources>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# AudioVibe 架构全景图
|
||||
|
||||
> 自动生成于 2026-05-19 | 基于 `master` 分支最新代码
|
||||
> 更新于 2026-05-22 | 基于当前未提交代码的文字说明同步,图表未重新生成
|
||||
|
||||
---
|
||||
|
||||
@ -104,6 +104,16 @@ app/src/main/java/com/audio/vibe/
|
||||
│ │ ├── MusicManagerViewModel.kt # 状态管理 + 事件驱动
|
||||
│ │ └── LazyPlaybackControllerProvider.kt # 播放控制器懒加载
|
||||
│ │
|
||||
│ ├── player/
|
||||
│ │ ├── PlayerScreen.kt # 完整播放页 + 进度拖动 + 模式/队列入口
|
||||
│ │ ├── PlayerViewModel.kt # PlaybackState -> PlayerUiState
|
||||
│ │ ├── PlayerUiState.kt # 播放页 UI 状态模型
|
||||
│ │ ├── MiniPlayerBar.kt # 音乐管理页底部迷你播放条
|
||||
│ │ ├── MiniPlayerState.kt # 迷你播放条状态映射
|
||||
│ │ ├── PlayerQueueSheet.kt # 当前队列弹窗
|
||||
│ │ ├── PlayerBottomSheet.kt # 播放链路/参数弹窗
|
||||
│ │ └── CoverImageLoader.kt # 封面加载与占位
|
||||
│ │
|
||||
│ ├── editor/
|
||||
│ │ └── TagEditorScreen.kt # (Demo) 标签编辑
|
||||
│ ├── voicechanger/
|
||||
@ -119,6 +129,7 @@ app/src/main/java/com/audio/vibe/
|
||||
│ ├── model/
|
||||
│ │ ├── ScannedAudioTrack.kt # 扫描音轨实体
|
||||
│ │ ├── PlaybackTrack.kt # 播放音轨实体
|
||||
│ │ ├── PlayMode.kt # 列表循环/顺序/单曲/随机
|
||||
│ │ └── AudioFormatCapability.kt # 格式能力模型
|
||||
│ └── repository/
|
||||
│ └── MusicScannerRepository.kt # 仓库接口契约
|
||||
@ -135,10 +146,10 @@ app/src/main/java/com/audio/vibe/
|
||||
│ │ └── AudioScanFingerprint.kt # 增量扫描指纹
|
||||
│ │
|
||||
│ └── playback/
|
||||
│ ├── AudioPlaybackController.kt # 双引擎控制器 (~1178行)
|
||||
│ ├── AudioPlaybackService.kt # 前台服务 + 通知栏
|
||||
│ ├── AudioPlaybackController.kt # 双引擎控制器 + 队列/模式/seek
|
||||
│ ├── AudioPlaybackService.kt # 前台服务 + MediaSession + 通知栏
|
||||
│ ├── PlaybackServiceController.kt # 解耦接口
|
||||
│ └── PlaybackSystemState.kt # 状态投影
|
||||
│ └── PlaybackSystemState.kt # MediaSession/通知栏状态投影
|
||||
│
|
||||
└── common/
|
||||
└── text/
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# Codex 交接摘要
|
||||
|
||||
最后更新:2026-05-15
|
||||
最后更新:2026-05-22
|
||||
|
||||
新开 Codex 会话时,优先把这个文件作为短上下文。
|
||||
|
||||
@ -20,6 +20,9 @@ AudioVibe Android App。技术栈是 Kotlin + Compose + MVVM + Flow + Room/Pagin
|
||||
- `PlaybackTrack` 是通过 id 查询的轻量播放投影。
|
||||
- `AudioPlaybackService` 持有唯一的 `AudioPlaybackController`。
|
||||
- UI 只能通过 `PlaybackServiceController` 调用播放能力。
|
||||
- `ui/player` 已有完整播放页、当前队列弹窗、播放链路弹窗和迷你播放条。
|
||||
- 播放模式包括列表循环、顺序列表、单曲循环和随机播放;随机播放时当前列表 UI 应显示真实随机队列。
|
||||
- 通知栏使用 MediaStyle,紧凑区 3 个按钮:上一曲、播放/暂停、下一曲。
|
||||
|
||||
## 必须保持的规则
|
||||
|
||||
@ -28,6 +31,10 @@ AudioVibe Android App。技术栈是 Kotlin + Compose + MVVM + Flow + Room/Pagin
|
||||
- MediaStore 和 SAF 的重复判断使用规范化后的 `sourcePath`,不是原始 URI。
|
||||
- 不要因为进入音乐管理页就启动播放服务。
|
||||
- 播放服务绑定失败时,不要伪造 UI 播放状态。
|
||||
- 清空曲库时,如果播放服务已存在,需要同步 `stop()` 并清空 UI 的迷你播放条状态。
|
||||
- 自然切曲应参考手动切曲路径,避免先发布 `ENDED/isPlaying=false` 的 UI 中间态。
|
||||
- 播放错误信息用 Toast 短暂提示,不要在播放页常驻展示错误条。
|
||||
- 进度条拖动时,UI 层可以保持按钮显示稳定,但不要为了 UI 闪动修改播放 controller 的真实状态语义。
|
||||
- 清空曲库前必须等待旧扫描任务真正取消。
|
||||
- 通知栏不要因为播放进度 tick 每秒刷新。
|
||||
- 不要对所有普通文件都跑 FFprobe,只有必要时再用。
|
||||
@ -45,20 +52,25 @@ AudioVibe Android App。技术栈是 Kotlin + Compose + MVVM + Flow + Room/Pagin
|
||||
- `app/src/main/java/com/audio/vibe/data/playback/PlaybackSystemState.kt`
|
||||
- `app/src/main/java/com/audio/vibe/domain/model/AudioFormatCapability.kt`
|
||||
- `app/src/main/java/com/audio/vibe/domain/model/PlaybackTrack.kt`
|
||||
- `app/src/main/java/com/audio/vibe/domain/model/PlayMode.kt`
|
||||
- `app/src/main/java/com/audio/vibe/domain/model/ScannedAudioTrack.kt`
|
||||
- `app/src/main/java/com/audio/vibe/domain/repository/MusicScannerRepository.kt`
|
||||
- `app/src/main/java/com/audio/vibe/ui/musicmanager/MusicManagerScreen.kt`
|
||||
- `app/src/main/java/com/audio/vibe/ui/musicmanager/MusicManagerViewModel.kt`
|
||||
- `app/src/main/java/com/audio/vibe/ui/player/PlayerScreen.kt`
|
||||
- `app/src/main/java/com/audio/vibe/ui/player/PlayerViewModel.kt`
|
||||
- `app/src/main/java/com/audio/vibe/ui/player/MiniPlayerBar.kt`
|
||||
|
||||
## 当前验证命令
|
||||
|
||||
```bash
|
||||
./gradlew testDebugUnitTest
|
||||
./gradlew assembleDebug
|
||||
```
|
||||
|
||||
## 建议下一步
|
||||
|
||||
1. Review 当前未提交的播放服务改动,重点看生命周期和通知栏行为。
|
||||
1. Review 当前未提交的播放服务和播放页改动,重点看生命周期、通知栏、自然/手动切曲和 UI 状态稳定性。
|
||||
2. 在真机上验证 MediaStore + SAF 的去重,覆盖内置存储、SD 卡和 U 盘。
|
||||
3. 如果设备可用,补充或执行通知栏控制的设备测试。
|
||||
4. 只针对 Media3 无法可靠播放的格式继续完善 FFmpeg 播放链路。
|
||||
@ -71,4 +83,3 @@ AudioVibe Android App。技术栈是 Kotlin + Compose + MVVM + Flow + Room/Pagin
|
||||
当前项目是 AudioVibe Android App。所有回答用中文。不要执行 git 操作。
|
||||
本次任务是:<在这里写具体任务>。
|
||||
```
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# 音乐扫描流程
|
||||
|
||||
最后更新:2026-05-15
|
||||
最后更新:2026-05-22
|
||||
|
||||
## 入口
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
- `ScanRequested` 调用 `repository.scanAudio(...)`
|
||||
- `scanFolder(uri)` 调用 `repository.scanFolder(uri, ...)`
|
||||
- `ResetRequested` 会先对当前扫描任务执行 `cancelAndJoin()`,确认旧扫描停止后再清空 Room。
|
||||
- `ResetRequested` 会先对当前扫描任务执行 `cancelAndJoin()`,确认旧扫描停止后再停止已存在的播放服务状态,最后清空 Room。
|
||||
|
||||
UI 应该在扫描过程中继续展示已有音乐库。扫描进度和分页列表是两条状态线,扫描写入 Room 后,Paging 列表应逐步反映新增歌曲。
|
||||
|
||||
@ -109,6 +109,7 @@ UI 应该在扫描过程中继续展示已有音乐库。扫描进度和分页
|
||||
- 新扫描歌曲写入 `MusicTrackEntity` 时必须使用 `id = 0L`。
|
||||
- DAO 的 `upsertTracks` 会通过 `sourcePath` 查已有记录,并复用已有数据库 id。
|
||||
- 不要把路径 hash 或扫描临时 id 写入 Room 主键。
|
||||
- 清空曲库后,播放状态、`playingId` 和迷你播放条也必须重置,避免 UI 继续引用已删除歌曲。
|
||||
|
||||
## 已知风险
|
||||
|
||||
@ -117,4 +118,3 @@ UI 应该在扫描过程中继续展示已有音乐库。扫描进度和分页
|
||||
- 过多并行 FFmpeg 任务会影响存储、CPU 和电量。
|
||||
- MediaStore 与 SAF 的路径规范化必须保持一致。
|
||||
- DAO 写入策略变化时,需要重新确认 FTS 是否保持同步。
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# 播放流程
|
||||
|
||||
最后更新:2026-05-15
|
||||
最后更新:2026-05-22
|
||||
|
||||
## 当前方向
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
1. 用户点击歌曲行的播放按钮。
|
||||
2. ViewModel 调用 `ensurePlaybackController()`。
|
||||
3. Provider 懒启动并绑定 `AudioPlaybackService`。
|
||||
3. Provider 通过 `get()` 懒启动并绑定 `AudioPlaybackService`。
|
||||
4. Service 通过 Binder 返回 `PlaybackServiceController`。
|
||||
5. ViewModel 按当前搜索词和分类,从仓库查询播放队列 id。
|
||||
6. ViewModel 调用 `controller.playQueue(queueIds, startTrackId, repository::playbackTrack)`。
|
||||
@ -29,9 +29,12 @@
|
||||
重要行为:
|
||||
|
||||
- 进入音乐管理页不应该启动播放服务。
|
||||
- 进入音乐管理页时只允许通过 `getIfRunning()` 观察已存在的播放服务;真正播放、迷你条控制、进入播放页时才允许启动服务。
|
||||
- 如果绑定服务失败,UI 不能伪造正在播放状态。
|
||||
- 当前播放队列应该等于当前可见查询/分类顺序。
|
||||
- 播放队列只保存 id,歌曲详情播放时再从 Room 查询。
|
||||
- 清空曲库时,如果播放服务已经存在,需要先停止播放服务状态,再清空 Room 和迷你播放条。
|
||||
- 迷你播放条在 `currentId != null` 时可见;退出音乐管理页再进入时,只要服务仍有当前歌曲,不论播放还是暂停都应恢复展示。
|
||||
|
||||
## Service 层
|
||||
|
||||
@ -51,6 +54,7 @@
|
||||
- 上一首
|
||||
- seek
|
||||
- 停止
|
||||
- 通知栏使用 Android 标准 MediaStyle,紧凑区显示 3 个动作:上一首、播放/暂停、下一首。
|
||||
- App 任务被移除时,通过 `android:stopWithTask="true"` 和 `onTaskRemoved` 停止服务。
|
||||
|
||||
生命周期方向:
|
||||
@ -70,12 +74,42 @@
|
||||
- 根据 id 从 Room 懒加载 `PlaybackTrack`。
|
||||
- 选择 Media3 或 FFmpeg 播放链路。
|
||||
- 通过 `StateFlow` 发布 `PlaybackState`。
|
||||
- 处理下一首、上一首、seek、停止、释放。
|
||||
- 处理播放模式、当前队列、下一首、上一首、seek、停止、释放。
|
||||
|
||||
播放后端:
|
||||
|
||||
- `Media3`:常见格式和系统解码链路。
|
||||
- `FfmpegAudioTrack`:FFmpeg 解码 PCM 后写入 AudioTrack,用于必须 FFmpeg 的格式或 Media3 不稳定参数。
|
||||
- Media3 在 `READY` 后如果 duration 仍为 `TIME_UNSET` 或小于等于 0,应复用 `onPlayerError` 路径并回退到 FFmpeg。
|
||||
- Media3 自然结束时应直接进入自然切曲逻辑,不能先发布一个 `ENDED/isPlaying=false` 的 UI 中间态。
|
||||
|
||||
## 播放模式和队列
|
||||
|
||||
相关文件:
|
||||
|
||||
- `PlayMode.kt`
|
||||
- `AudioPlaybackController.kt`
|
||||
- `PlayerQueueSheet.kt`
|
||||
|
||||
播放模式:
|
||||
|
||||
- `ListCycle`:列表循环。手动上一曲/下一曲在首尾循环;自然播放到尾曲后继续第一首。
|
||||
- `ListOnce`:顺序列表。手动上一曲/下一曲在首尾循环;自然播放到尾曲结束后暂停在当前歌曲,并允许再次点击播放重播当前歌曲。
|
||||
- `RepeatOne`:单曲循环。自然结束重播当前歌曲;解析失败时暂停,不继续跳下一首。
|
||||
- `Shuffle`:随机播放。当前队列 UI 展示真实随机顺序;随机顺序走到尾部再继续时,需要重新生成随机列表。
|
||||
|
||||
解析失败:
|
||||
|
||||
- 除 `RepeatOne` 外,解析失败按自然切曲处理。
|
||||
- 连续解析失败达到当前队列长度时停止播放,避免无限循环。
|
||||
- `ListOnce` 在列表末尾解析失败时停止播放。
|
||||
|
||||
当前队列 UI:
|
||||
|
||||
- 播放页可打开当前列表弹窗。
|
||||
- 队列显示顺序必须来自真实播放队列:随机播放时显示随机列表,非随机播放时显示原始列表。
|
||||
- 打开队列弹窗时首次滚动到当前播放项;弹窗保持打开期间,自然切曲不应强制回滚列表位置。
|
||||
- 点击队列歌曲按展示索引切曲。
|
||||
|
||||
## 格式路由
|
||||
|
||||
@ -113,12 +147,31 @@ FFmpeg 链路:
|
||||
- 错误
|
||||
- 是否有队列
|
||||
- 连续进度推进交给 MediaSession 的播放状态,不要每秒调用 `NotificationManager.notify()`。
|
||||
- 通知栏错误状态可以传给 MediaSession,但 App 页面不常驻展示错误条。
|
||||
|
||||
## 播放页和迷你播放条 UI
|
||||
|
||||
相关文件:
|
||||
|
||||
- `PlayerScreen.kt`
|
||||
- `MiniPlayerBar.kt`
|
||||
- `PlayerViewModel.kt`
|
||||
- `MiniPlayerState.kt`
|
||||
|
||||
重要行为:
|
||||
|
||||
- 播放页展示封面、歌曲名、歌手、专辑、播放进度、播放模式、当前队列、解码方式和播放链路。
|
||||
- 歌曲名、歌手名和封面区域需要保持稳定占位,切曲时不能因为占位图或文本高度变化造成页面跳动。
|
||||
- 歌曲名、歌手名在播放页和迷你播放条中显示不全时使用走马灯。
|
||||
- 进度条支持拖动 seek;拖动过程中 UI 进度不受后台播放进度覆盖,松手后 seek 到目标位置。
|
||||
- 播放页对 seek 后的按钮闪动可以在 UI 层做短暂显示保持,但不应改变 controller 的真实播放状态。
|
||||
- 播放失败信息通过 Toast 短暂提示,不在播放页常驻展示错误条。
|
||||
- 解码参数加载前保留上一帧参数,避免播放链路信息闪为空或短暂闪成错误链路。
|
||||
|
||||
## 已知风险
|
||||
|
||||
- FFmpeg PCM 链路当前使用 AudioTrack,不是 Oboe。
|
||||
- seek 当前主要支持 Media3;FFmpeg seek 还需要单独扩展。
|
||||
- 服务绑定会启动服务,因此必须保持懒加载,只在播放动作发生时触发。
|
||||
- 通知栏动作文案仍需检查多语言。
|
||||
- Android 13+ 需要处理通知权限,否则通知栏可能不可见。
|
||||
|
||||
- FFmpeg seek 通过重启 FFmpeg 管线实现,seek 到尾部附近若没有 PCM 输出应按自然结束处理,而不是报错。
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# AudioVibe 项目上下文
|
||||
|
||||
最后更新:2026-05-15
|
||||
最后更新:2026-05-22
|
||||
|
||||
## 产品定位
|
||||
|
||||
@ -37,13 +37,14 @@ AudioVibe 是面向海外用户的 Android 音频编辑与变声 App。当前重
|
||||
|
||||
- `data/playback`
|
||||
- `AudioPlaybackService.kt`:Android 播放服务、MediaSession、通知栏、对外播放接口。
|
||||
- `AudioPlaybackController.kt`:真实播放引擎、播放队列、Media3、FFmpeg PCM 到 AudioTrack、播放状态。
|
||||
- `PlaybackServiceController.kt`:服务对外暴露的窄接口,外部不应该直接拿到 `AudioPlaybackController`。
|
||||
- `AudioPlaybackController.kt`:真实播放引擎、播放队列、播放模式、Media3、FFmpeg PCM 到 AudioTrack、播放状态。
|
||||
- `PlaybackServiceController.kt`:服务对外暴露的窄接口,包含播放/暂停、上一曲、下一曲、seek、播放模式、队列索引播放和停止。
|
||||
- `PlaybackSystemState.kt`:通知栏和 MediaSession 状态映射。
|
||||
|
||||
- `domain/model`
|
||||
- `ScannedAudioTrack.kt`:完整的已扫描歌曲模型。
|
||||
- `PlaybackTrack.kt`:播放专用的轻量歌曲投影。
|
||||
- `PlayMode.kt`:列表循环、顺序列表、单曲循环、随机播放。
|
||||
- `AudioFormatCapability.kt`:格式能力表,包含是否可播放、是否需要 FFmpeg、标签是否可读写等。
|
||||
|
||||
- `domain/repository`
|
||||
@ -54,6 +55,12 @@ AudioVibe 是面向海外用户的 Android 音频编辑与变声 App。当前重
|
||||
- `MusicManagerViewModel.kt`:扫描状态、搜索/分类状态、播放状态接线。
|
||||
- `LazyPlaybackControllerProvider.kt`:只有真正播放时才启动并绑定播放服务。
|
||||
|
||||
- `ui/player`
|
||||
- `PlayerScreen.kt`:完整播放页,包含封面、播放控制、可拖动进度条、播放模式、当前队列入口和播放链路入口。
|
||||
- `PlayerViewModel.kt`:把 `PlaybackState` 映射为播放页 UI 状态,并转发播放控制事件。
|
||||
- `MiniPlayerBar.kt` / `MiniPlayerState.kt`:音乐管理页底部迷你播放条和状态映射。
|
||||
- `PlayerQueueSheet.kt` / `PlayerBottomSheet.kt`:当前队列弹窗和播放链路弹窗。
|
||||
|
||||
## 当前数据模型方向
|
||||
|
||||
- Room 的 `MusicTrackEntity.id` 是数据库自增 id。
|
||||
@ -65,11 +72,14 @@ AudioVibe 是面向海外用户的 Android 音频编辑与变声 App。当前重
|
||||
## 当前交互方向
|
||||
|
||||
- 音乐管理页是扫描和展示音乐库的主入口。
|
||||
- 音乐管理页进入时不启动播放服务;只有用户播放、控制迷你播放条或进入播放页时才启动/绑定服务。
|
||||
- 系统音乐扫描使用 MediaStore,覆盖常规系统已索引音频。
|
||||
- 文件夹/外置存储扫描使用 SAF,补充小众格式、SD 卡、U 盘。
|
||||
- 扫描过程中,已扫描歌曲应实时进入列表。
|
||||
- 摘要数量应和当前查询/列表状态一致。
|
||||
- 播放应通过服务和通知栏延续,不应因为退出音乐管理页就停止。
|
||||
- 播放错误在 UI 上用 Toast 短暂提示,不在播放页常驻展示错误条。
|
||||
- 播放页当前队列应跟真实播放顺序一致,随机播放时显示随机队列。
|
||||
|
||||
## 重要约束
|
||||
|
||||
@ -96,6 +106,8 @@ AudioVibe 是面向海外用户的 Android 音频编辑与变声 App。当前重
|
||||
- 音频格式能力标识
|
||||
- 播放状态和系统状态映射
|
||||
- 播放服务懒绑定
|
||||
- 播放模式和自然/手动切曲
|
||||
- 当前队列展示和队列索引播放
|
||||
- FFmpeg seek 到尾部附近的无 PCM 输出处理
|
||||
- 扫描缓存指纹过滤
|
||||
- Room 实体 id 映射
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# Review 检查清单
|
||||
|
||||
最后更新:2026-05-15
|
||||
最后更新:2026-05-22
|
||||
|
||||
检查扫描、播放、Room 或音乐管理相关改动时使用此清单。
|
||||
|
||||
@ -36,12 +36,19 @@
|
||||
- 歌曲详情通过 id 懒加载。
|
||||
- Media3 负责常规稳定格式。
|
||||
- FFmpeg PCM 链路负责必须 FFmpeg 的格式。
|
||||
- Media3 duration 无效时走错误回调并回退 FFmpeg,不直接让页面停在不可播放状态。
|
||||
- 自然切曲不先发布 `ENDED/isPlaying=false` 中间态;行为应尽量接近手动下一曲。
|
||||
- 顺序列表自然播放到最后一首结束后暂停在当前曲目,手动下一曲仍可循环到第一首。
|
||||
- 单曲循环解析失败时暂停;其他模式解析失败按自然切曲处理,连续失败达到队列长度后停止。
|
||||
- 随机播放的当前队列 UI 显示真实随机顺序,随机队列走到尾部继续时重新随机。
|
||||
- FFmpeg seek 到尾部附近没有 PCM 输出时按自然结束处理。
|
||||
- 不支持的输出参数只在播放兼容性需要时转换。
|
||||
- 日志打印原始参数和实际输出参数。
|
||||
|
||||
## 通知栏 / MediaSession
|
||||
|
||||
- 通知栏不会因为每次进度 tick 刷新。
|
||||
- 通知栏紧凑控制区包含上一曲、播放/暂停、下一曲三个按钮。
|
||||
- MediaSession 在播放、暂停、seek、切歌、错误、时长变化时更新进度锚点。
|
||||
- 通知栏动作调用 service/controller,不依赖 UI。
|
||||
- Android 13+ 通知权限需要被考虑。
|
||||
@ -54,6 +61,9 @@
|
||||
- 摘要数量和当前查询/列表状态一致。
|
||||
- 搜索栏和分类栏不会因为扫描消失。
|
||||
- 重置会先取消扫描,再清空数据库。
|
||||
- 重置曲库会同步停止已存在的播放服务状态并隐藏迷你播放条。
|
||||
- 新增 UI 不硬编码用户可见字符串。
|
||||
- 新增页面或组件时保留 Compose Preview。
|
||||
|
||||
- 播放页和迷你播放条的长歌曲名/歌手名使用走马灯或稳定占位,切曲不应导致布局跳动。
|
||||
- 播放错误信息使用 Toast 短暂提示,不在播放页常驻展示错误条。
|
||||
- 进度条拖动时,拖动中的显示进度不被后台进度覆盖;松手后按钮显示稳定,不通过修改播放层真实状态来遮蔽 UI 闪动。
|
||||
|
||||
@ -157,13 +157,13 @@ AI轻量化:本地AI变声(低延迟、保护隐私)+ 本地多格式播
|
||||
|
||||
高规格音频播放:支持高采样率与不同位深歌曲播放,优先保持原始采样率/位深输出;当设备或输出链路不支持时,自动进行高质量重采样/位深转换,并在播放详情中提示“原始规格”和“当前输出规格”
|
||||
|
||||
底部播放条:音乐管理页底部固定展示迷你播放条,显示封面缩略图、歌曲名、歌手、播放/暂停按钮和基础进度;没有播放内容时隐藏或展示轻量空态;点击播放条进入完整播放页
|
||||
底部播放条:音乐管理页底部固定展示迷你播放条,显示封面缩略图、歌曲名、歌手、播放/暂停按钮和基础进度;没有当前歌曲时隐藏;只要播放服务仍有当前歌曲,不论播放或暂停,退出音乐管理页后再次进入都应恢复展示;点击播放条进入完整播放页
|
||||
|
||||
完整播放页:播放页展示大封面、歌曲名、歌手、专辑、格式、采样率、位深、码率、时长、播放链路(Media3 直出、Media3 系统解码、FFmpeg PCM 兜底、重采样/位深转换等);支持进度拖动、播放/暂停、上一曲、下一曲;播放失败时展示失败原因和可尝试操作
|
||||
完整播放页:播放页展示大封面、歌曲名、歌手、专辑、格式、采样率、位深、码率、时长、播放链路(Media3 直出、Media3 系统解码、FFmpeg PCM 兜底、重采样/位深转换等);支持进度拖动、播放/暂停、上一曲、下一曲、播放模式切换和当前队列弹窗;播放失败时使用短暂 Toast 提示失败原因,不在页面中常驻错误条
|
||||
|
||||
通知栏与锁屏控制:播放时需要显示系统媒体通知,包含封面、歌曲名、歌手、播放/暂停、上一曲、下一曲和停止/关闭入口;通知栏、锁屏媒体控件、底部播放条和完整播放页必须共享同一播放状态;Android 13+ 需适配通知权限,Android 8.0+ 需使用前台服务通知渠道,用户拒绝通知权限时仍允许前台播放页控制,但后台播放能力需给出清晰提示
|
||||
通知栏与锁屏控制:播放时需要显示系统媒体通知,包含封面、歌曲名、歌手,以及上一曲、播放/暂停、下一曲三个核心控制按钮;必要时可通过删除通知或系统入口停止播放;通知栏、锁屏媒体控件、底部播放条和完整播放页必须共享同一播放状态;Android 13+ 需适配通知权限,Android 8.0+ 需使用前台服务通知渠道,用户拒绝通知权限时仍允许前台播放页控制,但后台播放能力需给出清晰提示
|
||||
|
||||
播放队列与状态:播放页和底部播放条共享同一播放状态;从搜索结果或分类列表播放时,应按当前列表顺序形成队列;切换搜索/分类不应打断正在播放的队列,除非用户主动播放新歌曲
|
||||
播放队列与状态:播放页和底部播放条共享同一播放状态;从搜索结果或分类列表播放时,应按当前列表顺序形成队列;支持列表循环、顺序列表、单曲循环和随机播放;随机播放时当前队列弹窗应展示真实随机队列而不是原始列表;切换搜索/分类不应打断正在播放的队列,除非用户主动播放新歌曲
|
||||
|
||||
交互要求:扫描速度≤5秒(100首常见格式歌曲),分类清晰,搜索响应≤0.5秒;底部播放条状态更新延迟≤300ms,通知栏媒体状态同步延迟≤500ms,进度拖动响应≤200ms;DSD、WV、高采样率 FLAC/WAV/ALAC 等大文件允许后台渐进式解析,不阻塞主界面
|
||||
|
||||
@ -349,11 +349,11 @@ Android版本:支持Android 8.0(API 26)及以上版本(覆盖90%以上
|
||||
|
||||
6. 文件访问:Android 10+ 使用 MediaStore + SAF 文件夹授权,持久化 URI 权限;大文件解析和波形生成统一在 Dispatchers.IO/后台任务执行,主线程只接收进度状态。
|
||||
|
||||
7. 播放状态架构:建立统一播放服务/播放仓库边界,封装 Media3 Player、FFmpeg PCM 兜底、AudioFocus、播放队列、播放进度和错误 Flow;Music Manager 底部播放条、完整播放页、后续变声/剪辑预览都应复用同一播放状态源,UI 页面只订阅 PlayerUiState,不直接操作播放器实例。
|
||||
7. 播放状态架构:建立统一播放服务/播放仓库边界,封装 Media3 Player、FFmpeg PCM 兜底、AudioFocus、播放队列、播放模式、播放进度和错误 Flow;Music Manager 底部播放条、完整播放页、通知栏和后续变声/剪辑预览都应复用同一播放状态源,UI 页面只订阅 PlayerUiState,不直接操作播放器实例。
|
||||
|
||||
8. 播放页能力展示:播放页必须展示当前播放链路、原始音频规格、实际输出规格、是否发生重采样/位深转换、是否使用 FFmpeg 兜底;这些信息来自播放层和扫描层的结构化状态,不通过字符串拼接临时推断。
|
||||
|
||||
9. 通知栏与锁屏媒体控制:播放服务需要接入 MediaSession/媒体通知,保证通知栏、锁屏控件、耳机/蓝牙媒体按键、底部播放条和完整播放页共享同一队列与播放状态;通知栏必须支持播放/暂停、上一曲、下一曲、停止/关闭,并正确处理 Android 13+ 通知权限、Android 8.0+ 通知渠道和前台服务生命周期。
|
||||
9. 通知栏与锁屏媒体控制:播放服务需要接入 MediaSession/媒体通知,保证通知栏、锁屏控件、耳机/蓝牙媒体按键、底部播放条和完整播放页共享同一队列与播放状态;通知栏紧凑区必须支持上一曲、播放/暂停、下一曲,并正确处理 Android 13+ 通知权限、Android 8.0+ 通知渠道和前台服务生命周期。
|
||||
|
||||
歌曲信息编辑方案:
|
||||
|
||||
@ -17,12 +17,12 @@ Changer,字体加粗,18sp);顶部下方为实时变声、离线变声切
|
||||
Cutter,字体加粗,18sp);底部为剪辑操作按钮栏(浅灰底色,无多余装饰),包含剪切、拼接、去噪、音量均衡功能(每个功能为“线性图标+文字”组合,图标24dp,文字14sp,排列紧凑,间距均匀,选中状态采用主题色,点击有轻微缩放反馈);核心区域为音频timeline(线性布局,占屏幕高度1/3,背景为浅灰,清晰显示动态音频波形,波形颜色与主题色一致),支持双指缩放、拖拽选择剪辑区域(选中区域采用主题色半透明底色,有细边框,区分明显);左侧为文件导入按钮(简约线性图标,24dp,点击有波纹反馈),右侧为格式转换选择框(简约圆角下拉框,无多余装饰,下拉选项采用简约列表,选中时有主题色提示);剪辑过程中显示“处理中”简约提示(无复杂动画,仅文字+简约加载图标,居中显示),处理完成后显示预览按钮(主题色文字按钮,点击有反馈);整体布局合理,timeline操作流畅,按钮大小适配单手点击,色调统一,无冗余元素,重点突出剪辑操作和timeline调整,适配不同屏幕尺寸(手机、平板),横屏/竖屏切换无界面错乱,timeline拖拽有轻微阻尼感,提升操作手感,参考GitHub高星音频剪辑项目UI质感。
|
||||
2.5 音乐管理模块UI提示词
|
||||
顶部采用沉浸式设计,左侧为线性返回按钮(24dp,点击有波纹反馈),中间为标题(Music
|
||||
Manager,字体加粗,18sp),右侧为简约圆角搜索框(占屏幕宽度2/3,placeholder提示“搜索歌曲/歌手”,浅灰色,无多余装饰,聚焦时有主题色边框,输入时显示清除按钮);核心区域为分类标签(歌曲、专辑、歌手、流派、格式,简约文字标签,字体14sp,选中状态有主题色下划线+轻微文字加粗,未选中状态为浅灰色,切换时有平滑过渡),下方为音频列表(简约列表样式,每个列表项包含专辑封面缩略图、歌曲名、歌手、格式/高规格标签,封面清晰无模糊,采用圆角8px);列表支持流畅滑动、批量选择(长按选中,显示删除、编辑标签按钮,按钮样式与整体统一,有视觉反馈),每个列表项右侧有播放/暂停按钮(简约线性图标,24dp,点击有波纹反馈),点击歌曲主体进入歌曲详情或编辑入口;页面底部固定迷你播放条,位于系统导航栏上方,显示封面缩略图、歌曲名、歌手、播放/暂停按钮和细进度条,播放条高度控制在56-64dp,不遮挡列表最后一项,列表底部需预留同等 padding;迷你播放条点击进入完整播放页,左右滑动播放条可切换上一首/下一首(如实现成本高可后续迭代);整体设计简洁有层次,分类清晰,搜索框视觉突出,列表加载流畅(有渐进式加载动效),无冗余元素,适配大量音频文件显示,深色/浅色模式下文字与背景对比度适中(符合无障碍设计),易读性强,列表项hover时有轻微背景色变化,提升交互体验,参考海外热门音乐管理App
|
||||
Manager,字体加粗,18sp),右侧为简约圆角搜索框(占屏幕宽度2/3,placeholder提示“搜索歌曲/歌手”,浅灰色,无多余装饰,聚焦时有主题色边框,输入时显示清除按钮);核心区域为分类标签(歌曲、专辑、歌手、流派、格式,简约文字标签,字体14sp,选中状态有主题色下划线+轻微文字加粗,未选中状态为浅灰色,切换时有平滑过渡),下方为音频列表(简约列表样式,每个列表项包含专辑封面缩略图、歌曲名、歌手、格式/高规格标签,封面清晰无模糊,采用圆角8px);列表支持流畅滑动、批量选择(长按选中,显示删除、编辑标签按钮,按钮样式与整体统一,有视觉反馈),每个列表项右侧有播放/暂停按钮(简约线性图标,24dp,点击有波纹反馈),点击歌曲主体进入歌曲详情或编辑入口;页面底部固定迷你播放条,位于系统导航栏上方,显示封面缩略图、歌曲名、歌手、播放/暂停按钮和细进度条,播放条高度控制在56-64dp,不遮挡列表最后一项,列表底部需预留同等 padding;迷你播放条仅在存在当前歌曲时显示,歌曲名/歌手名过长时使用走马灯,点击进入完整播放页;整体设计简洁有层次,分类清晰,搜索框视觉突出,列表加载流畅(有渐进式加载动效),无冗余元素,适配大量音频文件显示,深色/浅色模式下文字与背景对比度适中(符合无障碍设计),易读性强,列表项hover时有轻微背景色变化,提升交互体验,参考海外热门音乐管理App
|
||||
UI设计。
|
||||
2.6 播放页UI提示词
|
||||
完整播放页采用沉浸式音乐播放界面,顶部为返回按钮、标题或当前队列名称、更多操作按钮;主视觉区显示大尺寸专辑封面,封面为圆角12px以内,居中展示,不使用夸张阴影或复杂背景;封面下方展示歌曲名、歌手、专辑,标题最多两行,超长文本使用自然换行或省略,不能遮挡控制区;中部为播放进度条,支持拖动 seek,左右显示当前时间和总时长,拖动时显示准确时间反馈;核心控制区包含上一曲、播放/暂停、下一曲三个主按钮,播放/暂停按钮视觉最大但保持 Material 3 简洁风格,按钮使用线性或填充图标,不使用文字按钮代替常见图标;信息区展示格式、采样率、位深、码率、声道、原始规格、当前输出规格、播放链路(如 Media3、系统解码、FFmpeg PCM、重采样/位深转换),信息以紧凑列表或低饱和标签呈现,不做大面积卡片堆叠;播放失败时在信息区展示明确原因和可操作入口,如重试、另存为兼容格式、查看详情;播放页需要支持深色模式,夜间观看不刺眼,封面、文字和控制按钮保持足够对比度;从底部播放条进入和返回时使用轻量滑入/滑出动效,状态保持连续。
|
||||
完整播放页采用沉浸式音乐播放界面,顶部为返回按钮和当前队列入口;主视觉区显示大尺寸专辑封面,封面为圆角12px以内,居中展示,不使用夸张阴影或复杂背景,切曲时封面位置保持稳定,避免先闪占位图;封面下方展示歌曲名、歌手、专辑,文本区域固定高度,超长文本使用走马灯,不能遮挡控制区;中部为可拖动 seek 的进度条,左右显示当前时间和总时长,拖动时显示准确时间反馈,拖动中 UI 进度不被后台播放进度覆盖;核心控制区包含上一曲、播放/暂停、下一曲三个主按钮,播放/暂停按钮视觉最大但保持 Material 3 简洁风格,按钮使用线性或填充图标,不使用文字按钮代替常见图标;播放模式使用 PNG 图标表现列表循环、顺序列表、单曲循环、随机播放;当前队列入口弹出列表,正在播放歌曲高亮,点击歌曲切曲,随机播放时列表显示真实随机顺序;信息区展示格式、采样率、位深、码率、声道、原始规格、当前输出规格、播放链路(如 Media3、系统解码、FFmpeg PCM、重采样/位深转换),信息以紧凑列表或低饱和标签呈现,不做大面积卡片堆叠;播放失败时使用短暂 Toast 提示,不在页面中常驻错误条;播放页需要支持深色模式,夜间观看不刺眼,封面、文字、状态栏图标和控制按钮保持足够对比度;从底部播放条进入和返回时使用轻量滑入/滑出动效,状态保持连续。
|
||||
2.7 通知栏与锁屏媒体控制UI提示词
|
||||
系统媒体通知采用 Android 标准 MediaStyle,不做自定义复杂布局;通知内容显示专辑封面、歌曲名、歌手,操作按钮包含上一曲、播放/暂停、下一曲,必要时提供停止/关闭入口;通知图标使用单色线性小图标,深浅色系统通知中都保持可读;通知状态必须与 App 内底部播放条和完整播放页同步,暂停、切歌、播放失败时文案和按钮状态及时更新;锁屏媒体控件沿用系统样式,显示封面、歌曲名、歌手和基础控制;Android 13+ 未授权通知权限时,App 内应以简洁提示说明后台控制受限,不使用强制弹窗或阻塞式引导;通知渠道名称和说明保持简洁,避免营销化文案;播放停止后通知应及时移除或切换为可恢复播放状态,不能残留错误歌曲信息。
|
||||
系统媒体通知采用 Android 标准 MediaStyle,不做自定义复杂布局;通知内容显示专辑封面、歌曲名、歌手,紧凑操作按钮固定为上一曲、播放/暂停、下一曲三个核心控制;通知图标使用单色线性小图标,深浅色系统通知中都保持可读;通知状态必须与 App 内底部播放条和完整播放页同步,暂停、切歌、播放失败时文案和按钮状态及时更新;锁屏媒体控件沿用系统样式,显示封面、歌曲名、歌手和基础控制;Android 13+ 未授权通知权限时,App 内应以简洁提示说明后台控制受限,不使用强制弹窗或阻塞式引导;通知渠道名称和说明保持简洁,避免营销化文案;播放停止后通知应及时移除或切换为可恢复播放状态,不能残留错误歌曲信息。
|
||||
2.8 付费页面UI提示词
|
||||
简约高级,无冗余装饰,顶部采用沉浸式设计,左侧为线性返回按钮(24dp,点击有波纹反馈),中间为标题(Premium,字体加粗,18sp);核心区域为两种付费模式卡片(专业版、高级订阅),卡片采用圆角12px,轻微渐变底色+细边框,色彩与首页功能卡片色调一致(低饱和高级色),卡片有轻微悬浮感(阴影细腻),清晰显示付费价格(字体加粗,突出显示)、解锁权益(用简约对勾图标+文字,分点列出,清晰易读,对勾图标与主题色一致);免费版与付费版权益对比采用简约表格样式(无多余边框,文字清晰,付费版权益用主题色标注,对比鲜明);卡片下方为“购买”按钮(突出显示,主题色底色,白色文字,圆角8px,点击有明显缩放+波纹反馈),新增7天免费试用提示(浅灰色文字,12sp,标注“试用期结束自动扣费,可提前取消”,无突兀感);底部为退款政策、隐私政策文字链接(浅灰色,12sp,排列整齐,不突兀);整体设计无广告,重点突出付费权益和购买入口,流程清晰,符合海外用户付费习惯,视觉上简洁高级,无压迫感,卡片布局对称,间距均匀,加入细微动效(如卡片hover时有轻微上浮),提升质感,参考海外主流App付费页面设计逻辑。
|
||||
2.9 设置/基础功能UI提示词
|
||||
@ -22,6 +22,7 @@ jaudiotagger = "3.0.1"
|
||||
ffmpegKit = "6.0.1"
|
||||
media3 = "1.10.0"
|
||||
timber = "5.0.1"
|
||||
coil = "2.7.0"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
@ -58,6 +59,7 @@ jaudiotagger = { group = "net.jthink", name = "jaudiotagger", version.ref = "jau
|
||||
ffmpeg-kit-min = { group = "io.github.maitrungduc1410", name = "ffmpeg-kit-min", version.ref = "ffmpegKit" }
|
||||
androidx-media3-exoplayer = { group = "androidx.media3", name = "media3-exoplayer", version.ref = "media3" }
|
||||
timber = { group = "com.jakewharton.timber", name = "timber", version.ref = "timber" }
|
||||
coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user