Skip to content

Native Android client for Spotify, built with Jetpack Compose

Music video: look up clips only when wanted or the player is showing

liliapka25a2652fe82
diff --git a/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt b/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt
index 20ecb6e9..202252d6 100644
--- a/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt
+++ b/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt
@@ -328,7 +328,10 @@ object SongPlayer {
}
val mv = com.music.spotui.video.MusicVideoController
mv.onAudioBuffering(isBuffering, song.spotifyTrackId)
- if (!isBuffering && playing && mv.inForeground && (app.myspoti.power.EnergySettings.state.value.policy.allowBackgroundLookups || mv.wantVideo) && song.spotifyTrackId.isNotBlank())
+ // Clip lookup only where it can pay off: video wanted, or the player screen
+ // is up (toggle then is instant). Looking up every track by default cost
+ // searches and full-audio alignment downloads for users who never watch.
+ if (!isBuffering && playing && mv.inForeground && (mv.wantVideo || mv.hasPlayerScreen) && song.spotifyTrackId.isNotBlank())
com.music.spotui.video.MusicVideoController.prepare(song.spotifyTrackId, song.title, song.singer, durationMs)
if (!isBuffering && playing && mv.inForeground && app.myspoti.power.EnergySettings.state.value.policy.allowBackgroundLookups) {
com.music.spotui.data.api.LyricsApi.prefetch(lyricsTrack(song))
diff --git a/base/app/src/main/java/com/music/spotui/video/MusicVideoController.kt b/base/app/src/main/java/com/music/spotui/video/MusicVideoController.kt
index 62b62390..69c8e9bf 100644
--- a/base/app/src/main/java/com/music/spotui/video/MusicVideoController.kt
+++ b/base/app/src/main/java/com/music/spotui/video/MusicVideoController.kt
@@ -535,6 +535,9 @@ object MusicVideoController {
private var playerScreens = 0
+ /** A player screen is showing: the one place a clip lookup pays off unprompted. */
+ val hasPlayerScreen: Boolean get() = playerScreens > 0
+
/** A composed player screen still requests clip lookup after an app switch. */
@androidx.annotation.MainThread
fun attachPlayerScreen() { playerScreens++ }