Play Music Behind App? - ios

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.

Related

Swift - play sounds parallel with spotify

Is it possible to play a sound in swift when another one is being played, my client wants to make an app that emit sounds while spotify is playing songs too, is that possible ?
No you cant have multiple apps playing sounds at the same time.

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.

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.

iOS - Streaming Multitrack Audio

I'm building an app in which I need to steam multiple tracks of audio that make up a song. They all need to be synchronized so the song plays back naturally.
I've been able to play back local multitrack audio very well with the solution on this thread: multi track mp3 playback for iOS application, but it looks like AVAudioPlayer isn't able to stream.
I've been looking into working with DOUAudioStreamer because I've read that it's the best solution for streaming audio on iOS without going pretty low-level, but it seems to lack the equivalent of a -playAtTime: method, which is how the tracks were synced up using `AVAudioPlayer.
Does anyone know a workaround for this using DOUAudioStreamer, or have any advice on another way I should approach this? Thanks.

iPhone - What's the right audio player for my app?

I'm designing a music app that plays music from the user's iPhone music library and I'm having problems figuring out which audio player is the right one to use for it (AVAudioPlayer, AVPlayer, or MPMusicPlayer).
My app needs to do the following:
Play music from the iPhone music library
Control app music volume separately from device/system volume
Continue to play app music when app moves to background
Catch events when song changes to next song or finishes
From my research it seems like each of the three audio players mentioned above do SOME of the tasks required for my app, but none of them do ALL of them. AVPlayer seems to get the closest, except its volume is dependent on the device/system volume.
Does anyone have any recommendations or workarounds to accomplish this? I've been wracking my brain over this for quite some time so any help at all would be appreciated.
EDIT
The MPMusicPlayerController class does not actually support playing background audio when getting an instance of it via + applicationMusicPlayer. The best option, then, is to simply use MPMusicPlayer to query the iPod music library. Once a song is selected by the user, the resulting MPMediaItem can be queried for it's asset URL and fed into AVPlayer's +playerWithURL, giving you full control of playback parameters.
--
I would recommend MPMusicPlayerController.
MPMusicPlayerControllerhandles the low-level details of playing audio files in the iTunes library.
You can use the class method -applicationMusicPlayer to get a local copy of the iPod singleton; from there, you can control its volume by setting its volume property for just your application.
I would assume MPMusicPlayerController has background audio support already built in. If it doesn't, you can change your app's audio session context to make it work (see Playing background audio in http://www.sagorin.org/2011/11/29/ios-playing-audio-in-background-audio/)
You can setup any object you choose to be a KVO observer of your application-specific MPMusicPlayerController object. This way, you can be notified whenever the nowPlayingItem property is changed.
Hopefully this high-level description suffices. Let me know if you need any further clarification.

Resources