Control other apps music playing from inside my app? - ios

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.

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 Spotify background music in iOS app

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.

How to find out the current song playing on Spotify from an iOS app?

I'm developing an iOS app that needs to get the artist's name and the song's title from a track playing on Spotify in background.
This is the flow:
User is listening something on Spotify (web or native app)
User opens my app
App finds out which track is playing
Another track plays
App detects this and get the new track metadata
I tried to get that using the MediaPlayer framework (MPMusicPlayerController class) but nothing happens.
I looked in the Spotify SDK Api reference and found nothing too.
Is it possible ?
Thanks!

How does Audiobus for iOS work?

What SDK's does Audiobus use to provide inter-app audio routing? I am not aware of any Apple SDK that could facilitate inter-app communication for iOS and was under the impression that apps were sandboxed from each other so I'm really intrigued to hear how they pulled this off.
iOS allows inter-app communication via MIDI Sysex messages. AudioBus works by sending audio as MIDI Sysex message. You can read details from the developer himself:
http://atastypixel.com/blog/thirteen-months-of-audiobus/
My guess is that they use some sort of audio over network, because I've seen log statements when our app gets started even on a different device.
Don't really know about the details of the implementation, but this could be a way of staying in the "sandbox" constraint.
The Audiobus SDK (probably) use the Audio Session rules to "organize" all the sound output from the apps using their SDK, as you can see on their videos (on bottom of the page), the apps have an lateral menu to switch back and forwards between apps.
The Audio Session Category states:
Allows mixing: if yes, audio from other applications (such as the iPod) can continue playing when your application plays sound.
This way Audiobus can "control" the sound and allow the session to be persistent between the apps.

Is there any way I can make podcast application from iphone play my podcasts ? ( with code )

I'm doing an application that can play podcasts, but i feel more comfortable if the iPhone default podcast application plays the files, instead of me having to handle them.
When I pass the URL to the sharedApplication object, Safari opens and starts playing it ... but I'd like to skip the user seeing Safari. Is there any way?
The podcasts app does not have a public API. Therefore you cannot get it to play podcasts on your behalf.
Since the podcasts are added to your media library you should be able to find them with a media library query and start background playback easily.

Resources