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

[Feature request] Icy metadata #56

Open
Jei opened this issue Mar 17, 2020 · 32 comments
Open

[Feature request] Icy metadata #56

Jei opened this issue Mar 17, 2020 · 32 comments
Assignees
Labels
2 fixing enhancement New feature or request

Comments

@Jei
Copy link
Contributor

Jei commented Mar 17, 2020

First of all, thank you for making this plugin and audio_service, they're both great!
I'm trying to add support for Icy metadata to the Android version of the plugin, for a personal project. I've got a somewhat working solution here: https://github.com/Jei/just_audio/tree/icy-metadata.
ExoPlayer reads Icy metadata from Icecast/Shoutcast streams by default, so it doesn't require much additional code to make it work. The only problem I'm having is that I've only been able to read the IcyInfo part of the metadata, which includes the title and the URL (if supplied by the server), while I still cannot retrieve the IcyHeaders part, which contains other useful information about the stream (bitrate, genre...). If you have any insight on this issue, it would be appreciated.
I've got a couple of questions:

  • would this be something useful to have in the main repository?
  • how should I go about making this a non-breaking change?
@ryanheise ryanheise self-assigned this Mar 23, 2020
@ryanheise
Copy link
Owner

Thanks, Jei. I'd certainly be happy to accept a PR once you finish it as I think this could be useful to others. If you're only adding some more fields and a stream, I don't think that should break anything.

@pblinux
Copy link

pblinux commented Apr 10, 2020

Hello @Jei @ryanheise.

About the IcyInfo that's not retrieving, I think or it's a ExoPlayer issue or it's the DataSource, I'm not sure.

This are the things I tried so far:

  • Creating a DefaultHttpDataSourceFactory and adding a property Icy-MetaData", "1". Nothing changes.
DefaultHttpDataSourceFactory httpDataSource = new 
    DefaultHttpDataSourceFactory(Util.getUserAgent(context, "just_audio"), null);
httpDataSource.getDefaultRequestProperties().set("Icy-MetaData", "1");
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, httpDataSource);
  • Adding a audioAttribute to the player, nothing changes.
player.setAudioAttributes(new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MUSIC).setUsage(C.USAGE_MEDIA).build());
  • Using an external library: I found this metadata retriever and it works, this retrieves the icy-headers correctly:
    https://github.com/vsmaks/audiostream-metadata-retriever
    • The problem here, I think, that this makes an additional request for the data.
    • Also, it's outdated so I had to add tools:replace="android:label" to my project AndroidManifest

@Jei
Copy link
Contributor Author

Jei commented Apr 17, 2020

Thank you for the pointers @pblinux.
I've tried to add the ExoPlayer's OkHttp extension to use OkHttpDataSourceFactory instead of DefaultHttpDataSourceFactory, but it doesn't make any difference. However by logging the HTTP calls I was able to confirm that the Icy headers are being received correctly:

D/OkHttp  (22180): --> GET http://stream2.mpegradio.com:8070/tormented.mp3
D/OkHttp  (22180): Icy-MetaData: 1
D/OkHttp  (22180): User-Agent: just_audio/1.0.0 (Linux;Android 9) ExoPlayerLib/2.11.1
D/OkHttp  (22180): Accept-Encoding: identity
D/OkHttp  (22180): --> END GET
D/OkHttp  (22180): <-- 200 OK http://stream2.mpegradio.com:8070/tormented.mp3 (605ms)
D/OkHttp  (22180): icy-notice1: <BR>This stream requires <a href="http://www.winamp.com">Winamp</a><BR>
D/OkHttp  (22180): icy-notice2: SHOUTcast DNAS/posix(linux x64) v2.5.5.733<BR>
D/OkHttp  (22180): Accept-Ranges: none
D/OkHttp  (22180): Access-Control-Allow-Origin: *
D/OkHttp  (22180): Cache-Control: no-cache,no-store,must-revalidate,max-age=0
D/OkHttp  (22180): Connection: close
D/OkHttp  (22180): icy-name: -=- tormented radio -=- streaming since 1998
D/OkHttp  (22180): icy-genre: Industrial
D/OkHttp  (22180): icy-br: 128
D/OkHttp  (22180): icy-sr: 44100
D/OkHttp  (22180): icy-url: http://www.tormentedradio.com
D/OkHttp  (22180): icy-pub: 1
D/OkHttp  (22180): content-type: audio/mpeg
D/OkHttp  (22180): icy-metaint: 16384
D/OkHttp  (22180): X-Clacks-Overhead: GNU Terry Pratchett

Note that I didn't have to set the Icy-MetaData header manually, it's part of the request sent by ExoPlayer.
I'll keep looking.

@ryanheise ryanheise added 1 backlog enhancement New feature or request labels Apr 17, 2020
@Jei
Copy link
Contributor Author

Jei commented Apr 20, 2020

I've opened an issue in the ExoPlayer repository to ask for clarifications on how to retrieve IcyHeaders: google/ExoPlayer#7266

@pblinux
Copy link

pblinux commented Apr 21, 2020

Hello @Jei

I just tested what they said, it works.

onTracksChanged it's the way that exoplayer expose those headers.

@Override
	public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
		for (int i = 0; i < trackGroups.length; i++) {
			TrackGroup trackGroup = trackGroups.get(i);
			for (int j = 0; j < trackGroup.length; j++) {
				Metadata trackMetadata = trackGroup.getFormat(j).metadata;
				if (trackMetadata != null) {
					Log.d("just-audio:", trackMetadata.toString());
				}
			}
		}
	}

@Jei
Copy link
Contributor Author

Jei commented Apr 21, 2020

Hey @pblinux !
Yes, it's definitely the way to do it. I was working on a solution yesterday using onTracksChanged, however, I was only checking the first TrackGroup of the trackGroups array. It worked for my specific case, but your idea of iterating over the entire trackGroups array is probably safer. I'll commit the changes and work on the PR.

@ryanheise
Copy link
Owner

Thank, @Jei ! I've merged your PR and added a stub for iOS/macOS.

@oseiasmribeiro
Copy link

_audioPlayer.icyMetadataStream.listen(
(icyEvent) { ... }
); works well for android, but how to get the audio title on iOS?

@ryanheise
Copy link
Owner

It is not implemented on iOS yet. I've reopened this issue, and I'll note below a useful reference example for how I might be able to implement it:

https://stackoverflow.com/questions/27955125/timed-metadata-with-avplayer

@oseiasmribeiro
Copy link

@Jei Can you add this option also for iOS too? I'm not that expert yet. LOL I really need this in my project!

@Jei
Copy link
Contributor Author

Jei commented Jun 22, 2020

Hey @oseiasmribeiro! Unfortunately, I don't own any Apple device at the moment, so I don't think I'll be able to write and test the iOS version of these changes. It's also the reason why I released my current project only on the Play Store.

@oseiasmribeiro
Copy link

@Jei Ok. Thanks!

@silver-cap
Copy link

for iOS, not yet? If somebody helps, very very thanks.

@Okladnoj
Copy link

This is a very egregious question !!! And there are still no solutions (((

I spent 3 days on the Internet looking for a solution, but I did not achieve my goal.

Dear Developer please help us. Metadata is a very important part of any music file.
In the modern world without the name of the composition - no one needs you!

I will attach the results of my searches. I really hope that this will help you to improve the plugin)

1

You've @Jei seen it already. But there were updates. I started my search with this, but I was defeated

2

There are also 2 interesting codes here
1
2
I translated it all into swift

let playerItem = AVPlayerItem(url: url)
let metadataList = playerItem.asset.commonMetadata
for metaItem in metadataList {
    if let common = metaItem.commonKey {
        print("\(common)")
    }
}
let titleIndex = (avItem.asset.commonMetadata as NSArray).indexOfObject(passingTest: { obj, idx, stop in
    let metaItem = obj as? AVMutableMetadataItem
    if metaItem?.commonKey?.isEqual(toString: AVMetadataKey.commonKeyTitle) != nil {
        return true
    }
    return false
})

let item = avItem.asset.commonMetadata[titleIndex] as? AVMutableMetadataItem
let title = item?.value as? String

3

This is similar to the first link, but more expanded

4

Quite an interesting tip
Вот что у меня из этого получилось, но не сработало:

let url = URL(fileURLWithPath: st)
               let asset = AVAsset(url: url)
               let formatsKey = "playable"
               asset.loadValuesAsynchronously(forKeys: [formatsKey]) {
                   var error: NSError? = nil
                   let status = asset.statusOfValue(forKey: formatsKey, error: &error)
                   if status == .loaded {
                       for format in asset.availableMetadataFormats {
                           let metadata = asset.metadata(forFormat: format)
                           // process format-specific metadata collection
                           print("\(metadata)")
                       }
                   }
               }
               let metadataItems = asset.commonMetadata
               let metadataItem = AVMetadataItem.metadataItems(from: metadataItems, filteredByIdentifier: AVMetadataIdentifier.commonIdentifierArtwork)
               print(metadataItem);
               let playerItem = AVPlayerItem(url: url)
               let metadataList = playerItem.asset.commonMetadata
               for metaItem in metadataList {
                   if let common = metaItem.commonKey {
                       print("\(common)")
                   }
               }

5

I accidentally found code like this. I thought it would help, but I'm a noob in swift ((( And of course, nothing came of it ...

@Okladnoj
Copy link

Okladnoj commented Nov 20, 2020

@Jei
Please help us. tell me at least what needs to be changed at:
Project \ ios \ Runner \ AppDelegate.swift

some kind of temporary solution.

I hope my searches, in the previous post, will help you

@ryanheise
Copy link
Owner

I agree that this would be a very worthwhile feature to have on iOS, although please do keep in mind this is a collaborative effort. I will have my own priorities for which feature I will implement next (e.g. a visualiser and equaliser, or gapless looping), but other contributors may also have their own priorities, so if you can't wait for me alone to implement every single feature, it will just take the right contributor who is sufficiently motivated and wants this feature urgently enough to become a project contributor, and help out the project in the same way that @Jei graciously contributed the Android implementation.

Contributions are definitely welcome, even from those who are completely new to iOS and the Objective C programming language (several people have contributed Objective C code without having any prior experience with Objective C, so that is possible.)

@mohammadne
Copy link

mohammadne commented Dec 21, 2020

Hi, I don't have a deep knowledge about audio metadata or icy-metadata and difference between two but I am wonder to know that
is it possible to have audio thumbnail image (cover art) and description fields in metadata?

@blackraven96
Copy link

Still no one for added this functionnalty on IOS ? :)

@ryanheise
Copy link
Owner

@blackraven96 I am currently working on the visualiser feature, followed by nnbd (maybe this will come first), then maybe web assets/files, alongside bugs that crop up.

I have posted a link above on how this could be implemented, but it will just take someone sufficiently motivated to submit a pull request and jump the queue (otherwise if I implement it, it will happen after completing other items which are a higher priority for me personally).

Would you be interested in trying your hand at some Objective C code?

@ryanheise
Copy link
Owner

I feel I can increase my personal priority for this issue now. I would still at least like to get the visualizer feature published first and make the one-isolate branch of audio_service stable, but following that I'd like to get the iOS implementation of this feature implemented for completeness.

@Okladnoj
Copy link

We are waiting for your decision ...

@neutronstein
Copy link

Also waiting for this feature. Hope it gets implemented in the next few days :)
Thanks for your amaizing work

@ryanheise
Copy link
Owner

I'll hopefully make time for it this week. In the meantime, please post below some URLs of audio you would like me to use as this cases.

@neutronstein
Copy link

Fingers crossed. Currently building a radio app for iOS and metadata are missing.
https://www.radioking.com/play/note-radio

@ryanheise
Copy link
Owner

I will have a go at it tonight.

Note to self:

https://developer.apple.com/documentation/avfoundation/avplayeritemmetadataoutput?language=objc

@ryanheise
Copy link
Owner

I'm testing https://www.radioking.com/play/note-radio and am picking up the title.

Does anyone have more URLs to test, with more metadata?

@blackraven96
Copy link

Thx for your work :)

You can test with this streams :
http://str0.creacast.com/classique1
http://icecast.skyrock.net/s/natio_aac_64k?tvr_name=tunein16&tvr_section1=32aac
http://kissfm.ice.infomaniak.ch/kissfm-128.mp3

@ryanheise
Copy link
Owner

I've implemented iOS/macOS support in the latest commit. Note that all of the streams I tested only provided "title" metadata, and because I reverse engineered the keys from the metadata in those test URLs above, the title is the only metadata it is coded for. I will try to support other metadata keys if anyone provides a URL that exhibits them.

Let me know how it goes. One thing I wanted to be careful about was introducing a retain cycle. I don't think I've done that, but if you notice any memory leak (e.g. memory retained after player item or player itself is disposed), please let me know.

@ryanheise
Copy link
Owner

Any feedback/reports so far?

@neutronstein
Copy link

I was able to get current playing title on iOS. It worked well in simulator.

@APSchuurman
Copy link

Just ran into this issue and updating to latest version solved it.
Tested it on a real iOS device.

Thanks a lot for your great work.

@ryanheise
Copy link
Owner

Just to update, I've added support for the URL metadata on iOS. It's implemented in the fix/ios_livestream branch.

Will anyone be able to test this on their streams to confirm whether it works for you before I publish?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 fixing enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

10 participants