I want to play sound in my app (using swift) ,
in didFinishLaunchingWithOptions
function I wrote this
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
and I have a UIView
that holds the AVPlayer
.
I used:
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
self.becomeFirstResponder()
and remoteControlReceivedWithEvent
function. When the app enters background, the sound continues to play, but when I click pause button (which we use to play and pause sounds from outside the app) the remoteControlReceivedWithEvent
never get called!
Whats wrong?
in my project:
I call this in UITabbarViewController
-(BOOL)canBecomeFirstResponder{
return YES;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
make sure it can become first responder. remoteControlReceivedWithEvent in AVAudio is not being called