@@ -247,6 +247,7 @@ private data class AudioPresentationMetadata(
247247 val artwork : Bitmap ? ,
248248 val artist : String? ,
249249 val motionArtwork : ByteArray? = null ,
250+ val folderMotionArtworkUri : String? = null ,
250251)
251252
252253/* *
@@ -301,8 +302,19 @@ private object AudioPresentationMetadataCache {
301302 synchronized(cache) { cache.get(key) }?.let { return @withContext it }
302303
303304 // An old native retriever may still be unwinding; Android artwork must not wait for it.
304- if (isLocalArtworkSource(pathOrUri) && generator != app.gyrolet.mpvrx.preferences.ThumbnailGenerator .Native ) {
305- return @withContext AudioPresentationMetadata (artwork = repository.getArtwork(pathOrUri), artist = null )
305+ val localFolderMotion = app.gyrolet.mpvrx.domain.thumbnail.EmbeddedArtworkCandidates
306+ .audioFolderMotionPath(pathOrUri)
307+ if (
308+ isLocalArtworkSource(pathOrUri) &&
309+ generator != app.gyrolet.mpvrx.preferences.ThumbnailGenerator .Native &&
310+ generator != app.gyrolet.mpvrx.preferences.ThumbnailGenerator .MediaStore &&
311+ ! pathOrUri.startsWith(" content://" , ignoreCase = true ) &&
312+ localFolderMotion == null
313+ ) {
314+ return @withContext AudioPresentationMetadata (
315+ artwork = repository.getArtwork(pathOrUri),
316+ artist = null ,
317+ )
306318 }
307319 loadMutex.withLock {
308320 synchronized(cache) { cache.get(key) }?.let { return @withLock it }
@@ -340,22 +352,42 @@ private object AudioPresentationMetadataCache {
340352 }
341353 }
342354
343- val pictureBytes = if (explicitArtwork == null ) retriever?.embeddedPicture else null
355+ // Priority: embedded artwork, folder cover.jpg, then animated folder cover.mp4.
356+ val pictureBytes = retriever?.embeddedPicture
357+ val embeddedArtwork = retriever?.let {
358+ EmbeddedArtworkResolver .decodeRetrieverArtwork(it, pictureBytes)
359+ }
360+ val sidecarArtwork = if (embeddedArtwork == null ) {
361+ EmbeddedArtworkResolver .decodeAudioSidecar(cleanPath ? : pathOrUri)
362+ } else null
363+ // Keep a still image underneath while a selected motion cover buffers.
364+ val folderMotion = if (embeddedArtwork == null && sidecarArtwork == null ) {
365+ app.gyrolet.mpvrx.domain.thumbnail.EmbeddedArtworkCandidates
366+ .audioFolderMotionPath(cleanPath ? : pathOrUri)
367+ } else null
344368 AudioPresentationMetadata (
345- artwork = explicitArtwork ? : retriever?. let { EmbeddedArtworkResolver .decodeEmbeddedArtwork(cleanPath ? : pathOrUri, it, pictureBytes) } ,
369+ artwork = embeddedArtwork ? : sidecarArtwork ? : explicitArtwork ,
346370 artist = retriever?.let {
347371 it.extractMetadata(MediaMetadataRetriever .METADATA_KEY_ARTIST )
348372 ? : it.extractMetadata(MediaMetadataRetriever .METADATA_KEY_ALBUMARTIST )
349373 ? : it.extractMetadata(MediaMetadataRetriever .METADATA_KEY_AUTHOR )
350374 ? : it.extractMetadata(MediaMetadataRetriever .METADATA_KEY_COMPOSER )
351375 },
352376 motionArtwork = EmbeddedMotionArtwork .animatedBytes(pictureBytes),
377+ folderMotionArtworkUri = folderMotion,
353378 )
354379 } catch (_: Exception ) {
355380 val fallbackArtwork = explicitArtwork ? : if (cleanPath != null && ! isNetworkStream) {
356381 EmbeddedArtworkResolver .decodeSidecar(cleanPath)
357382 } else null
358- AudioPresentationMetadata (artwork = fallbackArtwork, artist = null )
383+ AudioPresentationMetadata (
384+ artwork = fallbackArtwork,
385+ artist = null ,
386+ folderMotionArtworkUri = if (fallbackArtwork == null ) {
387+ localFolderMotion
388+ ? : app.gyrolet.mpvrx.domain.thumbnail.EmbeddedArtworkCandidates .audioFolderMotionPath(cleanPath ? : pathOrUri)
389+ } else null ,
390+ )
359391 } finally {
360392 runCatching { retriever?.release() }
361393 }
@@ -663,6 +695,7 @@ private fun CoverArtCardImage(
663695 artworkUrl : String? = null,
664696 contentScale : ContentScale = ContentScale .Crop ,
665697 motionArtwork : ByteArray? = null,
698+ localMotionArtworkUri : String? = null,
666699 isPlaying : Boolean = false,
667700 remoteMotionQuery : MotionArtworkQuery ? = null,
668701 remoteMotionSurface : MotionArtworkSurface = MotionArtworkSurface .COVER ,
@@ -694,21 +727,14 @@ private fun CoverArtCardImage(
694727 val animatedDrawable = rememberMotionArtworkDrawable(motionArtwork)
695728
696729 Box (modifier.fillMaxSize()) {
697- if (animatedDrawable != null ) {
698- MotionArtworkImage (
699- drawable = animatedDrawable,
700- isPlaying = isPlaying,
701- fit = contentScale == ContentScale .Fit ,
702- modifier = Modifier .fillMaxSize(),
703- )
704- } else if (imageBitmap != null ) {
730+ if (imageBitmap != null ) {
705731 Image (
706732 bitmap = imageBitmap,
707733 contentDescription = null ,
708734 contentScale = contentScale,
709735 modifier = Modifier .fillMaxSize(),
710736 )
711- } else {
737+ } else if (animatedDrawable == null && localMotionArtworkUri == null ) {
712738 Box (
713739 modifier = Modifier .fillMaxSize(),
714740 contentAlignment = Alignment .Center ,
@@ -721,6 +747,22 @@ private fun CoverArtCardImage(
721747 )
722748 }
723749 }
750+ // Motion layers sit above the still cover; until the first decoded frame, the
751+ // embedded/folder artwork underneath remains visible.
752+ if (animatedDrawable != null ) {
753+ MotionArtworkImage (
754+ drawable = animatedDrawable,
755+ isPlaying = isPlaying,
756+ fit = contentScale == ContentScale .Fit ,
757+ modifier = Modifier .fillMaxSize(),
758+ )
759+ } else if (localMotionArtworkUri != null ) {
760+ LocalFolderMotionArtworkVideo (
761+ uri = localMotionArtworkUri,
762+ isPlaying = isPlaying,
763+ modifier = Modifier .fillMaxSize(),
764+ )
765+ }
724766 if (remoteMotionQuery != null && animatedDrawable == null ) {
725767 RemoteMotionArtwork (
726768 query = remoteMotionQuery,
@@ -753,6 +795,7 @@ private fun ImmersiveArtworkBackground(
753795 bitmap : Bitmap ? ,
754796 artworkUrl : String? ,
755797 motionArtwork : ByteArray? ,
798+ localMotionArtworkUri : String? ,
756799 remoteMotionQuery : MotionArtworkQuery ? ,
757800 isPlaying : Boolean ,
758801 landscape : Boolean ,
@@ -834,6 +877,7 @@ private fun ImmersiveArtworkBackground(
834877 bitmap = bitmap,
835878 artworkUrl = artworkUrl,
836879 motionArtwork = motionArtwork.takeUnless { reducedMotion },
880+ localMotionArtworkUri = localMotionArtworkUri.takeUnless { reducedMotion },
837881 remoteMotionQuery = remoteMotionQuery.takeUnless { reducedMotion },
838882 // Landscape keeps the square side-by-side cover, where a portrait Canvas would be cropped away.
839883 remoteMotionSurface = if (landscape) MotionArtworkSurface .COVER else MotionArtworkSurface .BACKGROUND ,
@@ -1387,7 +1431,8 @@ fun AudioPlayerControls(
13871431 val stableInsets = WindowInsets .systemBarsIgnoringVisibility.union(WindowInsets .displayCutout)
13881432 val showImmersiveArtwork = ! isTablet && immersiveArtworkEnabled && ! showVisualizer && ! showInPlaceLyrics &&
13891433 (albumArtBitmap != null || ! currentArtworkUri.isNullOrBlank() ||
1390- currentAudioPresentation?.motionArtwork != null || motionQuery != null )
1434+ currentAudioPresentation?.motionArtwork != null ||
1435+ currentAudioPresentation?.folderMotionArtworkUri != null || motionQuery != null )
13911436 // PlayerActivity uses light status-bar icons; the in-app player follows the app's bar style.
13921437 val useLightImmersiveHeaderContent =
13931438 if (showImmersiveArtwork && inAppSheet != null ) {
@@ -1459,6 +1504,7 @@ fun AudioPlayerControls(
14591504 bitmap = activeCoverOverride ? : albumArtBitmap,
14601505 artworkUrl = currentArtworkUri?.takeUnless { isLocalArtworkSource(currentMediaSource) },
14611506 motionArtwork = currentAudioPresentation?.motionArtwork?.takeIf { activeCoverOverride == null },
1507+ localMotionArtworkUri = currentAudioPresentation?.folderMotionArtworkUri?.takeIf { activeCoverOverride == null },
14621508 remoteMotionQuery = motionQuery?.takeIf { activeCoverOverride == null },
14631509 isPlaying = isPlaying,
14641510 landscape = ! isPortrait,
@@ -1828,6 +1874,7 @@ fun AudioPlayerControls(
18281874 artworkUrl = currentArtworkUri?.takeUnless { isLocalArtworkSource(currentMediaSource) },
18291875 contentScale = if (isAudiobook) ContentScale .Fit else ContentScale .Crop ,
18301876 motionArtwork = currentAudioPresentation?.motionArtwork?.takeIf { activeCoverOverride == null },
1877+ localMotionArtworkUri = currentAudioPresentation?.folderMotionArtworkUri?.takeIf { activeCoverOverride == null },
18311878 isPlaying = isPlaying,
18321879 remoteMotionQuery = motionQuery?.takeIf {
18331880 activeCoverOverride == null && ! showVisualizer && ! showInPlaceLyrics
0 commit comments