google / ExoPlayer

An extensible media player for Android
Apache License 2.0
21.62k stars 6k forks source link

Add util to convert Metadata into MediaMetadataCompat #5031

Open martijn00 opened 5 years ago

martijn00 commented 5 years ago

Issue description

Currently it's hard to extract metadata information and using it in the MediaSessionConnector. To make it easier i would suggest to add a conversion util that converts Metadata into a MediaMetadataCompat which can already be converted into a MediaDescriptionCompat.

This way it could be used to updated metadata on notifications, lockscreen and cast.

Reproduction steps

None

Link to test content

None

Version of ExoPlayer being used

2.9.0

Device(s) and version(s) of Android being used

All

A full bug report captured from the device

None

marcbaechinger commented 5 years ago

Currently it's hard to extract metadata information

From where do you extract that metadata?

martijn00 commented 5 years ago

For example in https://github.com/martijn00/XamarinMediaManager/blob/vNext/MediaManager/Platforms/Android/Media/PlayerEventListener.cs#L56

martijn00 commented 5 years ago

This would probably help devs with https://github.com/google/ExoPlayer/blob/release-v2/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/TimelineQueueEditor.java#L73 and https://github.com/google/ExoPlayer/blob/release-v2/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java#L692

By providing a standard way to extract metadata from tracks into MediaMetadataCompat we can easily show the info into the Notification of https://github.com/google/ExoPlayer/blob/release-v2/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L105

martijn00 commented 5 years ago

Also related to https://github.com/google/ExoPlayer/issues/3609

marcbaechinger commented 5 years ago

This would help you for providing a notification of the item which is currently playing and the metadata of the media session. You still have to provide MediaDescriptionCompat for queue items which have never been played. Do I understand correctly?

martijn00 commented 5 years ago

@marcbaechinger for me this would especially be useful when the ID3 tags of a media file are filled with in the metadata.

If it was possible to extract ID3 from a file or url into a MediaDescriptionCompat before actually playing would work for the before case. Like the existing MediaMetadataRetriever in Android, but then using Exoplayer.

For the MediaSessionConnector it would be useful to do the same, and provide a way to pass in ExoPlayer Metadata into a util that converts it into a MediaDescriptionCompat which then will be used in the notification.

Partial reason for all of this would also be performance, as it is hard to make a performant MediaMetadataRetriever implementation which handles things like covers etc.

martijn00 commented 5 years ago

@marcbaechinger Would it be an idea to add FFmpegMediaMetadataRetriever as a plugin for this?

See Usage of how they extract metadata.

I still think there are a lot of use cases for this issue, especially around the notifications and mediasession integration. Currently it's hard to get any information out of a media source in exoplayer. One of the examples given is:

@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
  for (int i = 0; i < trackGroups.length; i++) {
    TrackGroup trackGroup = trackGroups.get(i);
    for (int j = 0; j < trackGroup.length; j++) {
      Metadata trackMetadata = trackGroup.getFormat(j).metadata;
      if (trackMetadata != null) {
        // We found metadata. Do something with it here!
      }
    }
  }
}

There is just no way to actually do something with the metadata that is found there. It should be possible to create a list of MediaSource items based on Uri's and pass that to a ConcatenatingMediaSource. Based on that the metadata should be retrieved, and shown in the Notification.