androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.63k stars 386 forks source link

MediaSession Notification not loading `content://` URIs. #327

Open Guardiannw opened 1 year ago

Guardiannw commented 1 year ago

[REQUIRED] Use case description

Currently, the notification displayed from the MediaSession loads URIs from the web via https:// but it does not load content:// URIs. This is catalogued but never followed up in issue #9 at the final comment.

Proposed solution

Adjusted the Bitmap loader to also load content URIs.

Alternatives considered

None

marcbaechinger commented 1 year ago

There is DataSourceBitmpaLoader in the main branch that we will release with 1.1.0 I think.

This bitmap loader can handle content:// URIs.

Can you give a bit more detail what use case is not working with content:// URIs?

Because I actually thought that if a URI with content:// scheme is delivered to the System UI as artworkUri I'd actually expect that System UI would download that bitmap instead of the Media3 library.

Guardiannw commented 1 year ago

Thanks for the response Marc. So, the way that it seems to work right now, if the content URI is provided via artworkUri, it does work in some scenarios, such as in Android Auto, but it does not work with the default notification provided by MediaSession. I think this is just because the SimpleBitmapLoader doesn't support the content:// URIs by default. In the event a content:// URI is supplied currently, the notification simply has a white background with no image. It seemed like this should be something that is included since it is such a common thing, especially when working with media, however, the DataSourceBitmapLoader you mentioned might be an appropriate solution. Right now I have gotten around the issue by creating my own BitmapLoader, but it just seemed like something that should be supported by default.

marcbaechinger commented 1 year ago

Ah, yes sorry, my bad. It only works on API 33 without converting the URI to a bitmap, because before API 33 we need to use the largeIcon of the notification for it and this requires to use a byte array.

We will include the DataSourceBitmapLoader into 1.1.0 and also change the demo app to use this. I leave this enhancement open until we have done this. Thanks for reporting!

PaulWoitaschek commented 1 year ago

I'm not sure if I'm understanding the issue correctly, but I do use uris and they show notification images both on Api 33 as well as api 28 for instance:

https://github.com/PaulWoitaschek/Voice/blob/9b04e27feb27a32b3e660e7091e877bc2be93ece/playback/src/main/kotlin/voice/playback/session/ImageFileProvider.kt

https://github.com/PaulWoitaschek/Voice/blob/9b04e27feb27a32b3e660e7091e877bc2be93ece/playback/src/main/kotlin/voice/playback/session/MediaItemProvider.kt#L144