Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r2.16.0: How to get IcyHeaders? #9677

Closed
AndreasVogelfrei opened this issue Nov 10, 2021 · 4 comments
Closed

r2.16.0: How to get IcyHeaders? #9677

AndreasVogelfrei opened this issue Nov 10, 2021 · 4 comments
Assignees

Comments

@AndreasVogelfrei
Copy link

Up to version 2.15.1 I used "Player.Listener.onStaticMetadataChanged" to get the IcyHeaders (name, genre, bitrate) for audio streams.

As "Player.Listener.onStaticMetadataChanged" was removed in 2.16.0 none of the recommended replacements (like Player.getMediaMetadata, Player.Listener.onMediaMetadataChanged) seems to contain the IcyHeaders (name, genre, bitrate).

What is the recommended way with 2.16.0 to get the IcyHeaders?

@AndreasVogelfrei AndreasVogelfrei changed the title 2.16.0: How to get IcyHeaders? r2.16.0: How to get IcyHeaders? Nov 10, 2021
@christosts christosts self-assigned this Nov 10, 2021
@christosts
Copy link
Contributor

The ICY headers that you'd get in Player.Listener.onStaticMetadataChanged (name, genre, bitrate) are available in Format.metadata which you can get from Player.Listener.onTracksInfoChanged callback (note: Player.Listener.onTracksChanged is deprecated). This snippet should work

@Override
public void onTracksInfoChanged(TracksInfo tracksInfo) {
  for (TracksInfo.TrackGroupInfo groupInfo : tracksInfo.getTrackGroupInfos()) {
    if (groupInfo.getTrackType() == C.TRACK_TYPE_METADATA) {
      TrackGroup group = groupInfo.getTrackGroup();
      for (int i = 0; i < group.length; i++) {
        // ICY headers will be here.
        @Nullable Metadata metadata = group.getFormat(i).metadata;
      }
    }
  }
}

Let me know if this worked on your app.

@AndreasVogelfrei
Copy link
Author

AndreasVogelfrei commented Nov 12, 2021

Thanks a lot for your reply. It is working as expected with this implementation:

    @Override
    public void onTracksInfoChanged(EventTime eventTime, TracksInfo tracksInfo) {
        for (TracksInfo.TrackGroupInfo groupInfo : tracksInfo.getTrackGroupInfos()) {
            if (groupInfo.getTrackType() == C.TRACK_TYPE_METADATA) {
                TrackGroup group = groupInfo.getTrackGroup();
                for (int i = 0; i < group.length; i++) {
                    // ICY headers will be here.
                    @Nullable Metadata metadata = group.getFormat(i).metadata;
                    if(metadata != null) {
                        Log.v("TAG", "onTracksInfoChanged: IcyHeaders = " + metadata.toString());
                    }
                }
            }
        }
    }

Even if this is working it seems not very intuitive to find the IcyHeaders within this callback. May I suggest to implement a separate callback like "onIcyHeaderChanged" or similar?

Anyway, thanks a lot for your support. This question is resolved and can be closed.

@christosts
Copy link
Contributor

christosts commented Nov 15, 2021

Re-opening to improve how Icy headers are propagated to the app

@christosts christosts reopened this Nov 15, 2021
tonihei pushed a commit that referenced this issue Nov 18, 2021
Populate ICY headers into MediaMetadata so that they can
propagate to the app via AnalyticsListener#onMediaMetadataChanged().
This change copies IcyHeaders.name into MediaMetadata.description
and IcyHeaders.genre into MediaMetadata.genre.

Note: MediaItem.metadata maintain their precedence and overwrite any
ICY headers parsed.

Issue: #9677

#minor-release

PiperOrigin-RevId: 410495676
@tonihei
Copy link
Collaborator

tonihei commented Nov 18, 2021

Fixed by the commit above. The ICY headers will appear in onMetadataChanged as MediaMetadata.station and MediaMetadata.genre.

@tonihei tonihei closed this as completed Nov 18, 2021
tonihei pushed a commit that referenced this issue Nov 18, 2021
Populate ICY headers into MediaMetadata so that they can
propagate to the app via AnalyticsListener#onMediaMetadataChanged().
This change copies IcyHeaders.name into MediaMetadata.description
and IcyHeaders.genre into MediaMetadata.genre.

Note: MediaItem.metadata maintain their precedence and overwrite any
ICY headers parsed.

Issue: #9677

PiperOrigin-RevId: 410495676
icbaker pushed a commit to androidx/media that referenced this issue Nov 19, 2021
Populate ICY headers into MediaMetadata so that they can
propagate to the app via AnalyticsListener#onMediaMetadataChanged().
This change copies IcyHeaders.name into MediaMetadata.description
and IcyHeaders.genre into MediaMetadata.genre.

Note: MediaItem.metadata maintain their precedence and overwrite any
ICY headers parsed.

Issue: google/ExoPlayer#9677

#minor-release

PiperOrigin-RevId: 410495676
@google google locked and limited conversation to collaborators Jan 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants