0

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?

Sega-Zero
  • 3,034
  • 2
  • 22
  • 46
user3703910
  • 624
  • 1
  • 5
  • 25

1 Answers1

1

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

Community
  • 1
  • 1
nathanwhy
  • 5,884
  • 1
  • 12
  • 13