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

对着背影说爱祢 提交于 2019-11-29 21:05:37

问题


This question is an exact duplicate of:

  • Audio Information of Current Track iOS Swift 1 answer

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! :)


回答1:


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



来源:https://stackoverflow.com/questions/37198219/how-to-get-another-apps-currently-playing-audio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!