Spritekit- how to NOT stop audio from background music/podcast app - ios

I'm working on a game that has some simple sound effects, but would like it to not interrupt my music player which is on in the background (which happens as soon as I load sounds). Is this possible?

You may want to look into System Sound Services, I don't believe there's anyway to do it if you just want to use SpriteKit actions.

Related

AVAudioPlayer not playing after a while when app is in background

I am making an alarm clock app. To play the alarm sound at the appropriate time, I use myAudioPlayer.play(atTime: myAudioPlayer.deviceCurrentTime + secondsUntilAlarm). This way, even if the app is in the background, the audio player plays the alarm sound at the appropriate time.
Note: I got this idea from a different SO answer, which unfortunately I can't seem to find right now.
However, what I've noticed is that alarms are being played correctly if the secondUntilAlarm value is relatively soon, like maybe 20 minutes or less (converted to seconds of course since that's what the method requires). However, if it's longer than that, the sound does not play. Is there something I'm missing with how this method works in the background? Could the app be entering some sort of suspended state or something that disables the audio player from triggering the playback?
Any suggestions or comments would be appreciated--thanks!
So I've actually determined that it does not matter if the app enters the suspended state (in fact, this is expected). I've identified that the reason the alarm sound does not play sometimes because I open another app with audio that deactivates my app's audio session (therefore, it has nothing to do with the time the alarm is set for). To fix this, all I had to do was ensure I set .mixWithOthers for my app's audio session. That way, other audio sessions from other apps don't deactivate mine!

make my apps music/sfx stop if background audio is playing from a different app?

I'm looking to achieve the opposite effect of AVAudioSessionCategoryAmbientSolo.
Currently my options seem to be stick with solo(default) and have my app stop any pre playing music/sfx and play my apps music/sfx
or
I can use Ambient and have background audio mix with my apps music/sfx.
The effect I want is the opposite of solo. If the user is playing music or listening to a podcast from another app, then I dont want my app to play any sound. If the user isn't listening to anything else and starts my app, then my app can play it's music/sfx.
Seems ambient and solo are my only options unless I'm missing something.
If it has any bearing I'm using spritekit and swift.

Phonegap media stops system music

Phonegap media play method has a magic option playAudioWhenScreenIsLocked = false that does good job:
Prevents app music from playing when app is in background;
Makes app music obey the hardware "mute" button: without this option your app will ignore if user device is muted and play sound anyway.
But there is third hidden magic in this option. It stops current playing song from native Music app. Most of all it's annoying when I want to play short single sound.
Actually I would like to implement this scenario:
Music: Check if system music is playing on the app start. If it is not, play my app music, otherwise let user enjoy his own media.
Sound FX: Just play my little sound once and don't spoil anything.
And never play anything in background and when device is muted! Even if system Music app can let itself do so.
Has anyone managed to do something similar?
Thank you.
Ended up using https://github.com/floatinghotpot/cordova-plugin-nativeaudio (https://build.phonegap.com/plugins/2291)
Be aware: simple sound effects are not working in Simulator.

Pause / Play background audio from other apps

I know this is likely way outside of the sandbox but I thought I'd ask anyway:
I want to put a "pause / play" button in my app that will pause or play any background audio. Basically I'm looking to implement the play/pause button found in the multi-task bar.
A simple example is someone stars music with Pandora app, then launches my app. Is it possible to pause the background audio and resume it?
As a curiosity I have wondered if there was a way to create or broadcast the "remote control" events. Can I publish a pause/play event to the OS, perhaps?
I think here's what you're looking for. The trick is to loop a short audio file with silence when you want the other audio to stop. Then tell the iOS audio system when you're done, as suggested in the link.

How should I go about synchronizing sound effects with UI animations in iOS?

I want to play some sound effects while animating an UI element (e.g. playing a movement sound while an UI object is moving), which requires precise timing and synchronization.
I really can't figure out which framework I should be using from the descriptions in the Multimedia Programming Guide. So I need your kind help in choosing one.
What I want to do is:
Play short (max 10 seconds) sound effects (e.g. a button tap sound).
Being able to synchronize some of them with UI animations (e.g. a view appearance/disappearance).
I tried using the AudioServicesPlaySystemSound function from the AudioToolbox framework, sometimes it works great, but sometimes the sound won't play instantly. For example when a button is clicked, its action is performed before the sound is played, even though the AudioServicesPlaySystemSound is called first in the button's action method.
Thanks in advance,
Mota
Mixing audio waveforms into an already running RemoteIO Audio Unit configured with short buffers will have the lowest possible audio latency. The cost of this is a more complex to use API and the need for uncompressed audio assets.

Resources