Opening Siri stops AVAudioPlayer - ios

I am currently using an AVAudioPlayer to play looped music in the background of my app. However, when siri is opened in my application it turns it off. I am farly experienced with objective c but I cant seem to get this to work. Is there any way I can tell when a user opens siri so that I can start the AVAudioPlayer again after it stops. Please help!
P.S I have attempted continuously playing the audio but then siri wont work.

You can use AVAudioPlayerDelegate's audioPlayerEndInterruption:withOptions:
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player withOptions:(NSUInteger)flags {
[player play];
}

For anyone else coming to this, the endInterruption delegate isn't getting called from me when my app gets interrupted by Siri. I had to make the app resume playing when it becomes active again (using a notification).

Related

How can I avoid the AVPlayerLayer `setPlayer` audio blip?

I have an application that plays video using AVPlayer and AVPlayerLayer. In my app, I'm able to play audio when the app is locked by setting the player property of my AVPlayerLayer to nil when the application enters the background:
-(void)appEnteredBackgroundNotification:(NSNotification *)notification {
[[self playerLayer] setPlayer:nil];
}
However, when I do this, the audio will lag/blip for around 0.5 seconds. This sounds really really bad for the end user. Same goes for when the app enters foreground and I re-set the player property.
How can I avoid this audio blip? As a test I've tried removing the player in a background thread to no avail.
Update: I spoke with an Apple engineer at WWDC and they said that this issue is a bug on their end (so far not fixed in iOS 9) and this approach is the correct approach. Great...
I think may not you call pause before setting to nil and vice versa. And, try calling prepare before play.

Is it possible to start audio play when app is in the background in iOS?

Is it possible to start audio play when app is in the background?
When my app is in the background , it calls the method to play the sound but AvAudioPlayer doesnt play.
Ive gone through various links on the web regarding this but all I could find is how to continue playing audio when app goes in the background. So does this mean we can't start the audio play in the background?
Thanks in advance :)

How to mute background music in iOS

I have added music to my app so the music plays as soon as the app starts through the app delegate.
Now I have a switch in my app that I would like to rig up to where when it is switched off, the music stops playing, and when its switched back on, it resumes playing. Only problem is I don't know how to do this.
I know that I would need to make an IBAction and rig it to my switch but I am new to iOS Development and I learn best by being told how to do something and then applying it and seeing how it works in real time.
It would be great if someone could provide the code so I can throw it into my project and see how it works and learn from this.
Thanks.
When you pressing Mute button first check audioplayer is playing or not for exa.
if([avAudio isPlaying])
{
[avAudio pause];//OR[avAudio stop];
}
else
{
[avAudio play];
}

Pause all audio from the background - iOS Tweak

I am making a jailbroken iOS tweak and have a question. How can I stop all device audio while running from the background. Example: The user is playing Spotify and then clicks the power button on the device(turning off the screen and putting it to sleep) meanwhile Spotify is still playing music. At this point how can I stop stop all audio on the device(whether it's Spotify, default music app, Pandora, or whatever)? I have look into AVAudioSession and AVAudioPlayer but have not found a consistent reliable method to do this. I am testing this on a jailbroken iPhone5 running iOS7.0.4.
I am open to using AVAudioSession or AVAudioPlayer if it works consistently. I am also open to using something from a private framework to accomplish this. Thanks!
Thanks!
I figured it out, use this:
SBMediaController *mainMediaController = [%c(SBMediaController) sharedInstance];
[mainMediaController pause];

How to shut down the music in background mode on IOS program?

I make a iOS program to use the AVAudioPlayer to play music on the background. But I don't know how to shut down the music after a certain time.
I try to use the UILocalNotification to stop music in the method:
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notification
But the way only effectly after the user recieved the Notification and click to shut down!
How can I stop the music automatically after a certain time?
If you use AVPlayer instead of AVAudioPlayer you can achieve this using addBoundaryTimeObserverForTimes:queue:usingBlock:
I have tried this with AVQueuePlayer (which is a subclass of AVPlayer) and it worked.
Try something like this:
id observer = [avPlayer addBoundaryTimeObserverForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:CMTimeMake(60, 1)]] queue:NULL usingBlock:^{
[avPlayer pause];
}];
And somewhere later:
[avPlayer removeTimeObserver:observer];
I would love to be proved wrong, but I believe that what you're asking to do might be impossible. My impression is that if the user actually clicks the Home button to send your app into the background, it can't function as a "sleep timer", because you can't run a timer. Apple's own apps can do this sort of thing, but they have special privileges.
For example, look at this app:
https://itunes.apple.com/us/app/music-sleep-timer/id320583424?mt=8
Look at how he says, "Remember to keep this app in the foreground!" Clearly that's because once the app is background, the timer stops working.
You might be better off advising the user to resort to the countdown timer in Apple's Clock app. It can shut down your music and put the device to sleep.

Resources