Skip to content

Commit 856b369

Browse files
tianyifcopybara-github
authored andcommitted
DemoPlaybackService: catch exception when loading an artwork bitmap
When there is an error loading the bitmap we want to skip the bitmap population instead of throwing an error that crashes the app. PiperOrigin-RevId: 761995989
1 parent 6440344 commit 856b369

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

demos/session_service/src/main/java/androidx/media3/demo/session/DemoPlaybackService.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,16 @@ open class DemoPlaybackService : MediaLibraryService() {
193193
if (artworkUri == null) {
194194
builder.setArtworkData(ByteString.EMPTY)
195195
} else {
196-
val bitmap = mediaLibrarySession.bitmapLoader.loadBitmap(artworkUri).await()
197-
val outputStream = ByteString.newOutput()
198-
bitmap.compress(Bitmap.CompressFormat.PNG, /* quality= */ 90, outputStream)
199-
builder.setArtworkData(outputStream.toByteString())
196+
try {
197+
val bitmap = mediaLibrarySession.bitmapLoader.loadBitmap(artworkUri).await()
198+
if (bitmap != null) {
199+
val outputStream = ByteString.newOutput()
200+
bitmap.compress(Bitmap.CompressFormat.PNG, /* quality= */ 90, outputStream)
201+
builder.setArtworkData(outputStream.toByteString())
202+
}
203+
} catch (e: Exception) {
204+
// Bitmap loading failed. Do nothing.
205+
}
200206
}
201207
}
202208
builder.build()

0 commit comments

Comments
 (0)