iphone - iOS MPMoviePlayerController playing audio in background -
I have MPMoviePlayerController which should play audio of video in the background and should be controlled by playing multitasking / control control.
- (zero) startBackgroundStreaming {[[ UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [Self-made first responder]; NSError * activationError = Zero; AVAUDIO SESSION * AUDIO SESSION = [AVIDIO SASH Shared Instance]; [AudioSession SetDigitNet: Evolutionary Character Playback Error: & amp; activation error;]; [Audio session set active: yes error: & amp; activation error]; }
} The app icon appears in the Multitasking Play / Pause Bar, but these buttons do not respond.
Thank you!
The missing pieces of the puzzle are getting you handling remote control events. (Zero) Remote Control Reakwete Event: (UIIvent *) Event by applying the method can be done in your application representative. In its simplest form, it will appear:
- (zero) remoteControlReceivedWithEvent: (UIEvent *) event {if (event.type == UIEventTypeRemoteControl) {switch (event.subtype) {case UIEventSubtypeRemoteControlTogglePlayPause: // Toggle Play Pause Break; Default: Break; Although this method is called on an application representative, but you can always post a notification with the event as an object, so that the visual controller of the movie player controller can get it. The event is, therefore, like: - (zero) remoteControlReceivedWithEvent: (UIEvent *) event {[[NSNotificationCenter defaultCenter] postNotificationName: @ "RemoteControlEventReceived" object: event]; } Then grab the incident item in the listener list you assign to the notification
- (zero) remoteControlEventNotification:. (NSNotification *) Note {UIEvent * event = Note.bizject; If (event.type == UIEventTypeRemoteControl) {Switch (event.subtype) {Case UIEventSubtypeRemoteControlTogglePlayPause: if (_moviePlayerController.playbackState == MPMoviePlaybackStatePlaying) {[_moviePlayerController pause]; } And {[_moviePlayerController play]; } break; // you get the idea. Default: Break; }}}
Comments
Post a Comment