Control Spotify background music in iOS app - ios

I'm making an app that uses gestures to change the current background music e.g Pause, Skip, etc. Currently I can do this fine for music that is playing through the native MPMusicPlayerController class.
However I am unable to control the music when it is coming from Spotify (or other music playing apps for that matter). I believe this is to do with Apple's sandboxing policy between apps.
I'm not too hopeful, but does anyone know a way to trigger a universal music control notification? Something similar to what must happen on the iOS lockscreen when background music is playing? All my research tells me this almost definitely done through a private API, but am unable to get confirmation.
Alternatively, is there any Spotify specific way to achieve this?

Unfortunately the answer is No.
You can't get any information/Notifications about other apps, even regarding what's now playing.
As you wondered, it's all regarding the Sandboxing policy of Apple.

Related

Control music of other apps within my app

I'm currenty trying to find out if it's possible to control the music of other apps, e.g. Spotify, within my app. The two solutions I found are:
using the SDK of the specific service (e.g. Spotify SDK)
take over the audio session in my app, but this only allows me to stop/ play the music
I'm trying to find a solution that provides me with pause, play, forward, backward control and access to the title, maybe also the cover. Then I came across the "Sony Headphones Connect" app. It has a page with media control buttons, the title of the current song and is does not require any kind of sing in to Spotify or something else.
Picture is from the app from the App Store, I tested the controls and they work.
So somehow it must be possible, does anyone have an idea how I can achieve my desired result or how the "Sony Headphones Connect" app is handling this issue?
I think I found the answer, the "Sony Headphones Connect" app is controlling the music over bluetooth. So it's not directly possible to control the music of another app.

Control other apps music playing from inside my app?

Inside my app I'd like to have a control to stop/play, skipToNext and goToPrevious song if any other app is already playing music. Similar to what the control-center does already, but I wand those buttons to be available inside my app.
I've seen that MPMusicPlayerController allows that for the Apple Music app using skipToPreviousItem(), skipToBeginning(), skipToNextItem(). But I'm looking for a solution that would work for any other app (SoundCloud, Spotify, Deezer, ...), similarly as the control-center does.
Is there any way to control other apps music playing from inside my app?
There are two potential workarounds:
A) There is a Spotify App Remote SDK now https://github.com/spotify/ios-app-remote-sdk#sptappremoteuserapi. You can use that to control the Spotify app directly.
B) If you can live with only controlling stop/play you can take over the audio session which will stop Spotify and then end your session hoping that Spotify will automatically resume.

Does AVPlayer stop the user's music?

I want to know -- what happens to a user's music when an AVPlayer starts to play? Does nothing happen, does it stop, or does the action cancel itself? If so, how would I check and see if the user is playing music?
Apple's Documentation for this confused me.
Alright, looking up the info for this, it seems that AVAudioPlayer objects only interrupts the user's audio if the app's AVAudioSession's category is set to Solo Ambient, the default.
I saw this answer: App with AVPlayer plays mp4 interrupt iPod music after launched
I also saw this table in the Apple Developer documentation that explains whether or not different categories interrupt the user's music, with examples of different scenarios, including one for a game: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Sound.html#//apple_ref/doc/uid/TP40006556-CH44-SW1
In order to not interrupt the user's music, I need to set this to Ambient.

Play Music Behind App?

I recently released my app on the app store and one of my friends noticed that he couldnt listen to his music and play the game at the same time because each time the scene switched the music was cut out. What kind of code would I use to fix this so people can play their own music in the background?
If you want to use ObjectAL this functionality is as simple as:
[OALSimpleAudio sharedInstance].allowIpod = YES;
You need to look into AVAudioSession. It provides the audio sessions categories which you can use to specify what should happen in the relationship between your sounds and other sounds.

Mute IPhone prorammatically is legal?

I gonna start working on an app that have basic functionality to mute phone(no sound from any app, ring tone).
I searched over net and found some private api's to do what I want.
Mute iPhone programatically
https://github.com/forensix/BBSettings
But found some articles saying that Apple will not approve such kind of apps. And when I searched over store I got an app link below
https://itunes.apple.com/us/app/autosilent/id474777148?mt=8
This is auto silent app, that put iphone to mute state.
So now I want all my seniors to let me know whether I can do this app or not?
The application that you mentioned has the purpose of muting the phone. Someone downloading it expects it to mute the phone. That's probably why it was accepted on the store.
If your app mutes the phone, and the user didn't expect it, they could very likely miss important phone calls unexpectedly, which could be very damaging. So you would need a very, very good reason to have that functionality in your code.

Resources