Skip to content

r2.16.0: How to get IcyHeaders? #9677

Closed

Description

@AndreasVogelfrei

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?

Activity

  1. changed the title [-]2.16.0: How to get IcyHeaders?[/-] [+]r2.16.0: How to get IcyHeaders?[/+] on Nov 10, 2021
  2. self-assigned this
    on Nov 10, 2021
  3. christosts commented on Nov 11, 2021

    @christosts
    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.

  4. AndreasVogelfrei commented on Nov 12, 2021

    @AndreasVogelfrei
    Author

    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.

  5. christosts commented on Nov 15, 2021

    @christosts
    Contributor

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

  6. tonihei commented on Nov 18, 2021

    @tonihei
    Collaborator

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

  7. locked and limited conversation to collaborators on Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions