Update retrieving-metadata on ExoPlayer.dev

#minor-release

PiperOrigin-RevId: 371939159
This commit is contained in:
samrobinson 2021-05-04 18:08:08 +01:00 committed by bachinger
parent d4592c2a5a
commit 837826c735

View File

@ -4,14 +4,33 @@ title: Retrieving metadata
## During playback ## ## During playback ##
Media metadata can be retrieved during playback in multiple ways, depending on The metadata of the media can be retrieved during playback in multiple ways. The
the exact needs. Possible options are to listen to `onTracksChanged`, to listen most straightforward is to listen for the
to `onStaticMetadataChanged` or to add a `MetadataOutput` to the player. `Player.EventListener#onMediaMetadataChanged` event; this will provide a
[`MediaMetadata`][] object for use, which has fields such as `trackTitle` and
`albumArtist`. Alternatively, calling `Player#getMediaMetadata` returns the same
object.
~~~
public void onMediaMetadataChanged(MediaMetadata mediaMetadata) {
if (mediaMetadata.trackTitle != null) {
handleTrackTitle(mediaMetadata.trackTitle);
}
}
~~~
{: .language-java}
If an application needs access to specific [`Metadata.Entry`][] objects, then it
should listen for `Player#onStaticMetadataChanged` (for static metadata from the
`Format`s) and/or add a `MetadataOutput` (for dynamic metadata delivered during
playback) to the player. The return values of these callbacks are used to
populate the `MediaMetadata`.
## Without playback ## ## Without playback ##
If playback is not needed, it is more efficient to use the If playback is not needed, it is more efficient to use the
[`MetadataRetriever`][] to extract media metadata because it avoids having to [`MetadataRetriever`][] to extract the metadata because it avoids having to
create and prepare a player. create and prepare a player.
~~~ ~~~
@ -65,5 +84,7 @@ for (int i = 0; i < trackGroups.length; i++) {
~~~ ~~~
{: .language-java} {: .language-java}
[`MediaMetadata`]: {{ site.exo_sdk }}/MediaMetadata.html
[`Metadata.Entry`][]: {{ site.exo_sdk}}/metadata/Metadata.Entry.html
[`MetadataRetriever`]: {{ site.exo_sdk }}/MetadataRetriever.html [`MetadataRetriever`]: {{ site.exo_sdk }}/MetadataRetriever.html
[`MotionPhotoMetadata`]: {{ site.exo_sdk }}/metadata/mp4/MotionPhotoMetadata.html [`MotionPhotoMetadata`]: {{ site.exo_sdk }}/metadata/mp4/MotionPhotoMetadata.html