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

Add convenience API for querying static metadata #7266

Closed
Jei opened this issue Apr 20, 2020 · 3 comments
Closed

Add convenience API for querying static metadata #7266

Jei opened this issue Apr 20, 2020 · 3 comments

Comments

@Jei
Copy link

Jei commented Apr 20, 2020

Searched documentation and issues

I've been looking at the issues in this repository regarding Icy metadata and Shoutcast streams, especially:

Question

I want to add metadata events to the just_audio Flutter plugin, which uses ExoPlayer in the Android version.
I'm trying to read the IcyInfo and IcyHeaders of a Shoutcast stream. Reading the aforementioned resources, plus this Medium article, I was under the impression that I could retrieve them by adding a MetadataOutput to the current player, like this:

	MetadataOutput metadataOutput = new MetadataOutput() {
		@Override
		public void onMetadata(Metadata metadata) {
			Log.d("just_audio", "New metadata. Length: " + metadata.length());
			for (int i = 0; i < metadata.length(); i++) {
				final Metadata.Entry entry = metadata.get(i);
				if (entry instanceof IcyHeaders) {
					Log.d("just_audio", "Headers");
				} else if (entry instanceof IcyInfo) {
					icyTitle = ((IcyInfo) entry).title;
					icyUrl = ((IcyInfo) entry).url;
					Log.d("just_audio", "Info");
				}
				broadcastPlaybackEvent();
			}
		}
	};

[...]

	player = new SimpleExoPlayer.Builder(context).build();
	player.addMetadataOutput(metadataOutput);

[...]

	DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "just_audio"));
	Uri uri = Uri.parse(url);
	mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
	player.prepare(mediaSource);

However, I'm receiving events that contain only IcyInfo metadata entries, and I can't figure out why. I've had the same result with several different streams. Am I doing something wrong during initialization?
I'm using ExoPlayer 2.11.4.

Link to test content

I've had the same result with all the Shoutcast streams I've tried. Some examples are:

The full code I'm using for the Flutter plugin is here: https://github.com/Jei/just_audio/blob/icy-metadata/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java
I'm currently developing a Flutter app on top of it: https://github.com/Jei/tormentedplayer/tree/develop

@icbaker
Copy link
Collaborator

icbaker commented Apr 20, 2020

The IcyInfo represents the "Metadata" section here: https://cast.readme.io/docs/icy#section-metadata It's parsed regularly throughout the stream, and the results are passed to MetadataOutput.onMetadata() as you've seen.

The IcyHeaders are only parsed once then the connection to the stream is established, and it's made available through the Format.metadata field.

So you should be able to retrieve the IcyHeaders object by moving your instanceof IcyHeaders check to anywhere that you have access to the track's Format object.

@Jei
Copy link
Author

Jei commented Apr 21, 2020

Thank you for the clarification. I'm working on a solution that uses Player.EventListener.onTracksChanged() to collect the IcyHeaders for the current track.

@ojw28
Copy link
Contributor

ojw28 commented Apr 21, 2020

@icbaker - We should probably make it easier for developers to know when static metadata has changed, and to retrieve the current static metadata from the player without having to trawl through all the Format objects themselves. Could we consider this an enhancement (i.e., provide a better API), rather than (or in addition to) a documentation candidate?

@ojw28 ojw28 changed the title How to retrieve IcyHeaders from a Shoutcast stream Add convenience API for querying static metadata Jun 9, 2020
@andrewlewis andrewlewis assigned Samrobbo and unassigned icbaker Jul 3, 2020
kim-vde pushed a commit that referenced this issue Oct 6, 2020
@ojw28 ojw28 removed the question label Nov 24, 2020
@ojw28 ojw28 closed this as completed Feb 4, 2021
@google google locked and limited conversation to collaborators Apr 6, 2021
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

4 participants