Open Jei opened 4 years ago
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.
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:
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
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.
I've opened an issue in the ExoPlayer repository to ask for clarifications on how to retrieve IcyHeaders: https://github.com/google/ExoPlayer/issues/7266
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());
}
}
}
}
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.
Thank, @Jei ! I've merged your PR and added a stub for iOS/macOS.
_audioPlayer.icyMetadataStream.listen( (icyEvent) { ... } ); works well for android, but how to get the audio title on iOS?
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
@Jei Can you add this option also for iOS too? I'm not that expert yet. LOL I really need this in my project!
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.
@Jei Ok. Thanks!
for iOS, not yet? If somebody helps, very very thanks.
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
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
@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
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.)
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?
Still no one for added this functionnalty on IOS ? :)
@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?
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.
We are waiting for your decision ...
Also waiting for this feature. Hope it gets implemented in the next few days :) Thanks for your amaizing work
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.
Fingers crossed. Currently building a radio app for iOS and metadata are missing. https://www.radioking.com/play/note-radio
I will have a go at it tonight.
Note to self:
https://developer.apple.com/documentation/avfoundation/avplayeritemmetadataoutput?language=objc
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?
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
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.
Any feedback/reports so far?
I was able to get current playing title on iOS. It worked well in simulator.
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.
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?
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: