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

This question already has an answer here:
Audio Information of Current Track iOS Swift
(1 answer)
Closed 6 years ago.
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! :)

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

Related

Is it possible to use the audio from external apps (eg. Spotify) running in the background as input to AvCaptureInput when developing an iOS App?

I've looked through all the posts online and the Apple Developer Documentation, but nothing seems to comment on this. I want to be able to live-record the audio coming from, say, Spotify or another app that's running in the background, and process this audio data in my own app. This seems to be possible on Android.
I haven't actually coded it out yet but I've read through the documentation fully and previous stackoverflow posts.

Audio playlist autoplaying queue on iOS

Greetings to all fellow front-end coders.
I have quite a headache because of Apple's autoplay policy. As you've probably experienced, you can't autoplay a video / audio element with sound without user interaction. (I'm referring to this)
I'm currently trying to create my own music web application that will support playlists. I work with the Next.js framework and use react-player as player. Since it does not natively support playlists, I created a two-player pendulum system, where one plays the current sound file and the other loads the next. Then their roles change.
Everything works great in all browsers, except those on iOS, because this player uses autoplay to start playing.
I've been worried about this for several days. I've already thought about letting an Apple product users press play button every time a song changes as a punishment, but of course it's not a good solution.
I think a lot of you have encountered this and you have certainly found a solution. Please help me :(

Can an iOS app passivly listen for a certain sound?

I know the iPhone responds to "hey Siri". Is there similar features that I can use in my app to listen for certain sounds? If so what is the name of the iOS framework to use?
No, there is no API for that. Hey Siri is part of the OS and has hardware-level support. Your app can only use the microphones while it’s running; there is support for keeping the app alive while it’s recording audio, but the battery impact would be severe—the device can’t go to sleep—so it would be extremely unlikely to pass app review. That said, if you’d like API support to be added in future, please file an enhancement request with the use case you have in mind.
Yes sure, you can implement a recorder that records from the microphone and then you check anything you may need from recorded files.
Btw, what do you mean by certain sounds?
I think it sounds a bit tricky so please elaborate on your question. What's the business reason? How will you perform "listen for certain sounds"? How do you check it for being "certain". I think it's quite a hard thing to do using iOS but maybe I got your question wrong.
UPDATE: According to your comment: yeah it's possible but not like "hey ios check if it's a gunshot" :)))
But I think you can do it by checking the volume of the sound. If it is loud then it's a gunshot. I think it will work since user will use it on purpose. Check this link.
Also, I saw a similar app for gun shooters. So I'm sure it's doable:)
So shortly: find the way to: 1. use microphone. 2. Listen to sounds. 3. Check the sound for volume/length 4. Try detecting by testing
PS: Be careful with shooting while coding :)
If your "certain" sounds are referring to spoken words. Apple has the Speech Recognition framework for determining particular words.
If you are trying to measure perhaps a particular frequency however, Like many guitar tuner apps use or other music recording type app, I would recommend checking in depth AVFoundation 's guide to audio engineering.

iOS : is it really impossible to get info of current track being played in third-party apps (like Spotify)?

So far, I have red many conflicting answers about this.
In this SO thread, it is said to use:
let player = MPMusicPlayerController.systemMusicPlayer()
if let mediaItem = player.nowPlayingItem {
// ...
}
However, this only works with the iOS player. If the current song is being played by Spotify for example, mediaItem will be nil.
I understand that Apple's policy doesn't allow to access any other application's data. The only thing I am able to do right now is to know if a song is playing from another player with the help of AVAudioPlayer's secondaryAudioShouldBeSilencedHint and isOtherAudioPlaying.
I want to know, however, if there is another way to access it, like using Spotify framework? (I am absolutely non familiar with it, that's just making assumptions).
Thanks for your help.
I am not sure about iOS but the current track can be read from Spotify on a Mac via AppleScript. I use this technique from Objective C. If you're interested I can post the code.
Spotify publish their API for AppleScript here https://developer.spotify.com/applescript-api/
If you're looking for a generic way of determining what is playing then I think that you will be disappointed. Each application will have a different way of retrieving this information.
So yes and no. If you want to specifically only check if Spotify is playing, then perhaps the Spotify iOS SDK provides functionality for such a thing. I really don't know about that SDK's functionality.
I would venture to guess that your actual goal is to see if any third party framework is playing; Pandora, Tidal, Apple Music, Amazon Prime Music, etc. In which case, you would need a framework for each one that provided such functionality.
Apps are sandboxed from each other for security, so yes, there is no way to tell the current track information other than if you have the framework in place and it provides that functionality.

Detecting which audio track is playing on device in iOS Swift

I'm creating a mood tracking app that, among other things, should use information about the songs the user listens to. Specifically, I'm interested in just extracting the titles that are otherwise visible from the locked screen view, when a track is playing. I've search the interwebs and have had no luck finding a solution to access this data using Swift.
Can anyone help?
The short answer is no.
You may be able to retrieve song information from the iTunes library (if it's not a shared song using Home Sharing). Read about MPMusicPlayerController for more information. Specially the nowPlayingItem is probably what you're looking for.
However, most third-party applications such as Spotify, Deezer or Pandora will most likely have implemented their own player, which does not integrate with the iPod music player. This blog post also covers some of the details.
It is not about your ask, but it is about theme.
I made a code to get information about track in Itunes Media, and if you need get album art or correctly track name or artist, well I think it is will help you. The code is free to use in github.
ItunesSearch

Resources