A cross platform Audiobookshelf client for Android and iOS
Dart
Show the cover on the watch for downloaded books
Barnabasb2ab514790a5
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dartindex 156f7359..bcb15221 100644--- a/lib/services/audio_player_service.dart+++ b/lib/services/audio_player_service.dart@@ -5173,7 +5173,7 @@ class AudioPlayerService extends ChangeNotifier {// artist/chapter text but the car still shows old, the issue is downstream// of audio_service's MediaSession push.debugPrint(- '[Handler] mediaItem.add: item=$itemId title="${labels.title}" artist="${labels.subtitle}" dur=${displayDuration.round()}s chapter=$chapter hasHandler=${_handler != null}',+ '[Handler] mediaItem.add: item=$itemId title="${labels.title}" artist="${labels.subtitle}" dur=${displayDuration.round()}s chapter=$chapter hasHandler=${_handler != null} art=${coverUrl == null ? 'none' : coverUrl.startsWith('content:') ? 'content' : coverUrl.startsWith('file:') ? 'file' : coverUrl.startsWith('http') ? 'http' : 'other'}',);_handler!.mediaItem.add(MediaItem(diff --git a/packages/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java b/packages/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.javaindex a48d0e06..d8620f72 100644--- a/packages/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java+++ b/packages/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java@@ -271,6 +271,7 @@ public class AudioService extends MediaBrowserServiceCompat {}}}+ bitmap = capArtSize(bitmap);artBitmapCache.put(artUriString, bitmap);return bitmap;} catch (Exception e) {@@ -279,6 +280,22 @@ public class AudioService extends MediaBrowserServiceCompat {}}+ // The Wear OS media controls bridge rejects session artwork above this+ // size ("Image is too large (1200x1200)") and shows a blank cover on the+ // watch. Downloaded covers are stored at 1200px; server covers arrive at+ // 800px and always worked. Every phone-side reader scales down anyway.+ private static final int MAX_ART_EDGE_PX = 800;++ private static Bitmap capArtSize(Bitmap bitmap) {+ if (bitmap == null) return null;+ int w = bitmap.getWidth();+ int h = bitmap.getHeight();+ int longest = Math.max(w, h);+ if (longest <= MAX_ART_EDGE_PX) return bitmap;+ float scale = (float) MAX_ART_EDGE_PX / longest;+ return Bitmap.createScaledBitmap(bitmap, Math.max(1, Math.round(w * scale)), Math.max(1, Math.round(h * scale)), true);+ }+private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {final int height = options.outHeight;final int width = options.outWidth;@@ -851,13 +868,13 @@ public class AudioService extends MediaBrowserServiceCompat {*/synchronized void setMetadata(MediaMetadataCompat mediaMetadata) {String artCacheFilePath = mediaMetadata.getString("artCacheFile");+ String artUri = mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI);if (artCacheFilePath != null) {// Load local files and network images, cached in filesartBitmap = loadArtBitmap(artCacheFilePath, null);mediaMetadata = putArtToMetadata(mediaMetadata);} else {// Load content:// URIs- String artUri = mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI);if (artUri != null && artUri.startsWith("content:")) {String loadThumbnailUri = mediaMetadata.getString("loadThumbnailUri");artBitmap = loadArtBitmap(artUri, loadThumbnailUri);@@ -866,12 +883,20 @@ public class AudioService extends MediaBrowserServiceCompat {artBitmap = null;}}+ android.util.Log.i("AbsorbArt", "setMetadata art="+ + (artCacheFilePath != null ? "file" : artUri == null ? "none" : artUri.substring(0, Math.min(8, artUri.length())))+ + " bitmap=" + describeBitmap(artBitmap));this.mediaMetadata = mediaMetadata;mediaSession.setMetadata(mediaMetadata);handler.removeCallbacksAndMessages(null);handler.post(this::updateNotification);}+ private static String describeBitmap(Bitmap b) {+ if (b == null) return "null";+ return b.getWidth() + "x" + b.getHeight() + " " + b.getConfig() + " " + (b.getByteCount() / 1024) + "KB";+ }+private MediaMetadataCompat putArtToMetadata(MediaMetadataCompat mediaMetadata) {return new MediaMetadataCompat.Builder(mediaMetadata).putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, artBitmap)