Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/src/androidTest/assets/metadata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Synthetic playback metadata fixture

`synthetic-playing-restore.flac` contains 30 seconds of generated mono silence,
original title/artist and three independent lyric tracks, with no artwork.
It contains no third-party audio or lyrics.

Regenerate from the repository root with FFmpeg:

```sh
ffmpeg -hide_banner -loglevel error \
-f lavfi -i anullsrc=r=16000:cl=mono -t 30 \
-c:a flac -sample_fmt s16 -map_metadata -1 \
-metadata title='Original title' \
-metadata artist='Original artist' \
-metadata album='Synthetic restore fixture' \
-metadata 'LYRICS=[00:01.00]original lyric' \
-metadata 'NERI_LYRICS_ORIGINAL=[00:01.00]original lyric' \
-metadata 'LYRICS_TRANSLATED=[00:01.00]original translation' \
-metadata 'NERI_LYRICS_ROMANIZED=[00:01.00]original romanization' \
app/src/androidTest/assets/metadata/synthetic-playing-restore.flac
```

`RestoredLocalPlaybackThreadTest.singleRestoreWhilePlayingPublishesOriginalMetadataToSessionAndNotification`
runs only on an API 37 emulator with notifications allowed and no existing
playback, playback service, sleep timer or sync target. It uses a private copy,
restores the saved queue and runtime preferences, and removes only its synthetic
history/statistics entries and temporary media files.
Binary file not shown.

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/src/main/java/moe/ouom/neriplayer/ui/NeriApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ import moe.ouom.neriplayer.ui.theme.NeriTheme
import moe.ouom.neriplayer.ui.theme.biasCoverSeedTowardBlue
import moe.ouom.neriplayer.ui.theme.rememberActualSystemDarkTheme
import moe.ouom.neriplayer.ui.util.rememberSongDisplayCoverUrl
import moe.ouom.neriplayer.ui.util.hasKnownEmptyLocalCover
import moe.ouom.neriplayer.data.model.NeteaseArtistSummary
import moe.ouom.neriplayer.data.model.BiliUploaderSummary
import moe.ouom.neriplayer.ui.viewmodel.playlist.BiliVideoItem
Expand Down Expand Up @@ -606,7 +607,7 @@ private fun NeriAppContent(
currentSong?.playbackVisualKeyAliases().orEmpty()
}
val playbackVisualCoverState = rememberPlaybackVisualCoverState(
playbackVisualCoverRequest(displayCoverUrl, currentSongVisualKey)
playbackVisualCoverRequest(displayCoverUrl, currentSongVisualKey, currentSong.hasKnownEmptyLocalCover())
)
val playbackVisualCoverUrl = playbackVisualCoverState.url
// 旋转重建时直接复用当前封面颜色,避免首帧回到默认主题
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ class SharedCoverFlightState {
}
}

internal fun clearArtwork() {
sourceBitmap = null
linkedBitmap = null
flightBitmap = null
}

internal fun reportTarget(bounds: Rect, cornerPx: Float) {
if (bounds.isEmpty) return
targetBounds = bounds
Expand Down Expand Up @@ -221,7 +227,7 @@ class SharedCoverFlightState {

/** 替代封面的位图和两端坐标齐备后才隐藏真实封面 */
val hidesCovers: Boolean
get() = flying || (linked && linkedBitmap != null && sourceBounds != null &&
get() = (flying && flightBitmap != null) || (linked && linkedBitmap != null && sourceBounds != null &&
(hasVisualTarget() || targetCoordinates?.isAttached == true))

fun beginLinked(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ fun NeriMiniPlayer(
coverIdentityKey: String? = null,
visualCoverIdentityKey: String? = null,
hasCurrentSong: Boolean = true,
tabletControls: moe.ouom.neriplayer.ui.component.playback.MiniPlayerTabletControls? = null
tabletControls: moe.ouom.neriplayer.ui.component.playback.MiniPlayerTabletControls? = null,
clearCover: Boolean = false
) {
moe.ouom.neriplayer.ui.component.playback.NeriMiniPlayer(
title = title,
Expand All @@ -47,7 +48,8 @@ fun NeriMiniPlayer(
coverIdentityKey = coverIdentityKey,
visualCoverIdentityKey = visualCoverIdentityKey,
hasCurrentSong = hasCurrentSong,
tabletControls = tabletControls
tabletControls = tabletControls,
clearCover = clearCover
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package moe.ouom.neriplayer.ui.component.playback

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.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.tween
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.CheckCircle
import androidx.compose.material.icons.outlined.MusicNote
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import moe.ouom.neriplayer.R as AppR
import moe.ouom.neriplayer.common.R as CoreCommonR
import moe.ouom.neriplayer.core.player.metadata.SongMetadataApplyStage
import moe.ouom.neriplayer.ui.haptic.HapticTextButton
import moe.ouom.neriplayer.ui.viewmodel.ManualMetadataApplicationState
import moe.ouom.neriplayer.ui.theme.NeriDesign
import moe.ouom.neriplayer.ui.theme.NeriMotion
import kotlin.time.Duration.Companion.milliseconds

private const val MetadataProgressAnimationMs = 240
private const val MetadataCompletionHoldMs = 280L

@Composable
internal fun ManualMetadataApplicationProgress(
state: ManualMetadataApplicationState,
onCancel: () -> Unit,
modifier: Modifier = Modifier,
requestKey: String = "metadata",
onCompleted: () -> Unit = {}
) {
val target = if (state.completed) 1f else
(state.stage?.ordinal ?: 0) / SongMetadataApplyStage.entries.size.toFloat()
val progress = remember(requestKey) { Animatable(target) }
val latestOnCompleted = rememberUpdatedState(onCompleted)
LaunchedEffect(requestKey, state.stage, state.completed) {
progress.animateTo(target, tween(MetadataProgressAnimationMs, easing = NeriMotion.Emphasized))
if (state.completed) {
val completedAt = withFrameNanos { it }
while (withFrameNanos { it } - completedAt < MetadataCompletionHoldMs.milliseconds.inWholeNanoseconds) {
// 按可见帧保留完成状态,后台等待不提前关闭窗口
}
latestOnCompleted.value()
}
}
Surface(
modifier.fillMaxWidth().testTag("metadata-application-progress"),
shape = NeriDesign.tokens.cardShape,
color = MaterialTheme.colorScheme.surfaceContainerHigh
) {
Column(
Modifier.fillMaxWidth().padding(20.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Icon(
if (state.completed) Icons.Outlined.CheckCircle else Icons.Outlined.MusicNote,
contentDescription = null,
modifier = Modifier.size(28.dp),
tint = MaterialTheme.colorScheme.primary
)
Text(
stringResource(if (state.completed) AppR.string.metadata_apply_completed else metadataApplyStageLabel(state.stage)),
modifier = Modifier.weight(1f).testTag("metadata-application-stage"),
style = MaterialTheme.typography.titleSmall,
minLines = 2,
maxLines = 2
)
}
LinearProgressIndicator(
progress = { progress.value },
modifier = Modifier.fillMaxWidth().height(5.dp).clip(NeriDesign.tokens.chipShape)
.testTag("metadata-stage-progress"),
trackColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.08f),
strokeCap = StrokeCap.Round,
gapSize = 0.dp,
drawStopIndicator = {}
)
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
stringResource(
AppR.string.metadata_apply_stage_count,
if (state.completed) SongMetadataApplyStage.entries.size else (state.stage?.ordinal ?: 0) + 1,
SongMetadataApplyStage.entries.size
),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Box(Modifier.height(48.dp), contentAlignment = Alignment.CenterEnd) {
if (state.isRunning) {
HapticTextButton(
onClick = onCancel,
enabled = state.canCancel,
modifier = Modifier.testTag("metadata-application-cancel")
) { Text(stringResource(CoreCommonR.string.action_cancel)) }
}
}
}
}
}
}

private fun metadataApplyStageLabel(stage: SongMetadataApplyStage?): Int = when (stage) {
SongMetadataApplyStage.FETCHING_DETAILS, null -> AppR.string.metadata_apply_fetching_details
SongMetadataApplyStage.FETCHING_LYRICS -> AppR.string.metadata_apply_fetching_lyrics
SongMetadataApplyStage.PREPARING_COVER -> AppR.string.metadata_apply_preparing_cover
SongMetadataApplyStage.PREPARING_METADATA -> AppR.string.metadata_apply_preparing_metadata
SongMetadataApplyStage.APPLYING -> AppR.string.metadata_apply_committing
}
Loading
Loading