8

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

halfer
  • 19,824
  • 17
  • 99
  • 186
modesitt
  • 7,052
  • 2
  • 34
  • 64
  • The code you post may return that info, but only if the other player it giving it to the `MPNowPlayingInfoCenter`. – Larme May 12 '16 at 22:14
  • I tested with both Apple Music and the stock Podcasts app @Larme. Am I implementing it incorrectly? – modesitt May 12 '16 at 23:24
  • 4
    The problem is that this is just impossible. You cannot get any information about what other applications are doing. Just imagine an app that would track what you are watching on youtube or in Safari. That would be a *huge* security threat. – Sulthan May 15 '16 at 19:54
  • @Sulthan However there appear to be some classes built into MediaItem that suggest otherwise. Also there is an app capability that suggests you can share app audio. – modesitt May 15 '16 at 19:56
  • 1
    Is using a jailbreak feature or API for recording the system audio an option for you? – Tomer May 15 '16 at 19:58
  • @Tomer preferably not I'm afraid. Maybe if it was a few years ago, but the Jailbreak community seems to have dwindled. Is there any stock iOS option? – modesitt May 15 '16 at 20:00
  • @Nucl3ic Sharing is a very different use case because it is triggered from the app that is playing the video, not from a random app in the background. – Sulthan May 15 '16 at 20:00
  • @Sulthan you are probably right. I just asked the question to see if anyone knew a way that this could be done. – modesitt May 15 '16 at 20:01
  • @Nucl3ic have you got any solution to get the audio details of another apps like pandora or what did you implement to achieve this. Please share. – Gypsa Jul 26 '17 at 01:53
  • @Gypsa this really isn't possible with current versions of iOS – modesitt Jul 26 '17 at 01:55
  • 1
    @Nucl3ic boseconnect app is giving the similar feature.. That app can control pandora songs. Any idea.. – Gypsa Jul 26 '17 at 02:04

1 Answers1

4

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

Pau Senabre
  • 4,155
  • 2
  • 27
  • 36