iOS 4.3 AudioQueuePause vs home button - ios

I use AudioQueue to play sound in my game. There are two sound objects: looped music and non-looped sfx. The problem that I observe is as follows:
The music is started.
The sfx is started.
The sfx is paused (using AudioQueuePause)
The game goes to background by Home Button.
I get UIApplicationWillResignActiveNotification and the music is paused (using AudioQueuePause).
I return to my app from iPad menu.
I get UIApplicationDidBecomeActiveNotification and the music is unpaused (using AudioQueueStart).
Note that I did not unpause sfx. In spite of that, it resumes and I can hear it!
I can only reproduce it on iPad with iOS 4.3 when going to background by Home Button. If I use Sleep/Wake button instead of Home, it works perfectly.
So it seems that the system somehow resumes all audio queues : even explicitly paused ones.
Any thoughts?

Related

How to check iOS APP [music play app] is on Background when APP is launched by the headset wire control

How to check iOS APP [music play app] is on Background when APP is launched by the headset wire control?
or quick music play like this
When we click on the quick song to play, in fact, the app has started and played the song, but the iOS system does not actively tell us that the program is in the background. In this case, how exactly do we know that the app is in the background and is separate from the normal home button background switch。
Or how do you distinguish this type of program startup
If you know when your app has started playing music (i.e. via a delegate method or callback or something), you can check the current state of the app by using UIApplication's applicationState property.

AVPlayer pausing when app become inactive. How to automatically restart when active

An AvPlayer will pause when the app goes in the background, and stays paused when the app goes back to the foreground. Is there an easy way to make the video play again (if it was playing when the background event happened) without having to do it manually for each AVPlayer ?
I see how I can have notification observers that will play my AVPlayers and that I will have to remove when the player gets deinit, but that's annoying.

How to stop MPMusicPlayerController from playing when application terminate by user?

I have the following situation in my application:
I have a music system in my application and I used MPMusicPlayerController to play music; every thing is working fine until now.
My problem: When a user starts playing music in my application and after some time it terminates, music cannot be stopped because I'm using the [MPMusicPlayerController systemMusicPlayer] object. I know there is another option which is applicationMusicPlayer, but it stops playing music in background, which doesn't satisfy my requirements.
How can I stop the music from playing when the application is terminated by user?
I have some code that attempts to stop it in applicationWillTerminate: but it only works in some situations:
If I press home button twice and terminate the app from the multitasking UI, then the app can stop the music player.
If I press the home button once and then go to the home screen, and after that I press the home button twice and terminate the application then it can not stop my music player.
I tried to put a breakpoint in applicationWillTerminate: but in the second example (from above), the application crashed and did not execute my code, unlike in the first situation.
UPDAT
And I know that when I use MPMusicPlayerController background mode is not required because it starts music in the native music player.
Any help would be appreciated.
Unfortunately your only option based on your requirements is to play the audio using your own app, AVAudioPlayer for example and set the audio background mode requirement.
As there is no way of receiving a notification when your app is terminated by the OS or by the user, you have no way around it, you will not be able to stop the system or application player from your process.
Registering for NSUncaughtExceptionHandler wont catch SIGKILL or SIGSTOP either so you cannot rely on the system music player.
This shouldnt be a problem though as its easy to setup audio playback in your app. If you are using the system player so that the user can play their own music, you should use a picker and access their music library so that they can choose the music.
In this case:
If I press the home button once and then go to the home screen, and after that I press the home button twice and terminate the application then it can not stop my music player.
You have to register application in the background mode.
fileprivate var backgroundTask: UIBackgroundTaskIdentifier = .invalid
func registerBackgroundTask() {
self.backgroundTask = UIApplication.shared.beginBackgroundTask {
//TODO
}
}
Call it in AppDelegate
Hope to help you

Preventing my app's audio from interfering with other background music

I think what I'm looking for is the combination of existing settings that I can't quite put together in the right order. I have an app that plays sound clips using AVAudioPlayer. There is a start/stop button.
I would like any other apps' audio to continue until my app actually needs to play something.
When my app is launched with some iTunes music playing, that music continues correctly. When I press play in my app, the other audio correctly stops, and my app plays. I stop my player, switch back to the music app, and press play again. But now when I switch back to my own app, the music stops immediately.
I would like it to again wait until it needs to play something before killing the music app.
My best guess is that once I've used the player, it is in some kind of 'I need audio' state, and remains in that state. How do I resign this state?

IOS - Accessing Audio Stream from Ipod, Pausing and Changing Volume

I am working on an app that needs to pause and unpause the audio stream coming from the ipod app. Is there any way to do that? I want to make a button that once you press it, it pauses the currently playing song on the ipod app. Pressing it again unpauses where the music left off. I am also working on a way to change the volume of the ipod app, is there anyway to do this that does not rely on the user manually moving a slider?
Any help at all would be great. Thanks!
you could use this framework if you want: Media Player Framework
Specially the MPMusicPlayerController Class
You have this:
Controlling Playback
– play
– pause
– stop
Managing Playback Mode and State
volume ( property )

Resources