Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get another app's currently playing audio [duplicate]

How can I access another app's currently playing audio - the actual audio item but metadata is welcome too. I can see that this question has been asked a lot but with few solutions being offered over the years. I understand apple's philosophy for probably not wanting an app to be able to do this. I also understand that such a request is probably outside of the iOS API. With that being said, I would really like some kind of solution.

Logically, I feel that

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo 

should return the info for whatever is currently playing; however, as others have mentioned, this value is always nil for audio being played outside of your app. Notably, popular audio apps seem to fail to use the MPNowPlayingInfoCenter class, making such audio fail to appear.

If using the default music app, one can use

MPMusicPlayerController.systemMusicPlayer().nowPlayingItem

However, what is a more consistent way to access audio playing through the podcasts app, Spotify, Pandora, Safari, etc?

Has anyone found a solution to this? Are there any old Objective-C frameworks that support this functionality?

One approach might be viable if there is there some way I can access the audio path of the item currently being played. For example, if I could get the path of the currently playing item, I could create an AV object from it:

AVAudioPlayer(contentsOfURL: audioUrl)

So is there a way I can get the audio url of the currently playing item and use it that way?

Is another approach better?

If a native solution does not exist, is it possible to bodge something together for it to work? Any advice or ideas welcome.

Edit: I don't believe anybody has been able to achieve this; however, I think a lot of people would like to. If this has been addressed, please link it! :)

like image 943
modesitt Avatar asked May 12 '16 22:05

modesitt


Video Answer


1 Answers

This isn't currently possible in iOS. Just changing your AVAudioSession category options to .MixWithOthers, what will be an option to get info Song Info from other apps, causes your nowPlayingInfo to be ignored.

iOS only considers non-mixing apps for inclusion in MPNowPlayingInfoCenter, because there is uncertainty as to which app would show up in (e.g.) Control Center if there are multiple mixing apps playing at the same time.

Proposal: An option would be to use a music fingerprinting algorithm to recognize what is being played by recording it from your App.

Some interesting projects in this direction:

Gracenote https://developer.gracenote.com/ Gracenote (which is owned by Sony) has opened up it's SDKs and APIs and has a proper dev portal.

EchoNest & Spotify API http://developer.echonest.com/ Fusioned with Spotify since March 2016

ACRCloud https://www.acrcloud.com/ offers ACR solutions for custom files such as TV commercials, music tec

like image 165
Pau Senabre Avatar answered Nov 14 '22 08:11

Pau Senabre