Commit 734e1abb by samrobinson Committed by bachinger

Update retrieving-metadata on ExoPlayer.dev

#minor-release

PiperOrigin-RevId: 371939159
parent 15b82741
Showing with 25 additions and 4 deletions
...@@ -4,14 +4,33 @@ title: Retrieving metadata ...@@ -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++) { ...@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment