I want to allow the controls from my keyboard to work in my app. The controls 
use Apple's Remote Control events (beginReceivingRemoteControlEvents, 
endReceivingRemoteControlEvents, and remoteControlReceivedWithEvent), however I 
cannot seem to get this to work with MPMoviePlayerController.

I do not see any events at the start of the program, even though 
beginReceivingRemoteControlEvents is called at the start.
I do not see any events during the playback of a video.
I do see events after I close the video.

>From the above, it seems that the audio stream of MPMoviePlayerController 
>disables the controls. However I do not know how to change this. I tried using 
>[moviePlayer setUseApplicationAudioSession:NO]; to change the audio to use the 
>system session, yet it does nothing.

Here is my setup. My app delegate is a UIViewController. I set the main 
window's root view controller to the app delegate, add views to the view 
controller and in the view controller for the parts which has to do with video.

- (BOOL)canBecomeFirstResponder {
    return YES;
}
- (void)tableView:(UITableView *)theTableView 
didSelectRowAtIndexPath:(NSIndexPath *)theIndexPath {
    NSString *file = [[MGMFilesPath stringByExpandingTildeInPath] 
stringByAppendingPathComponent:[files objectAtIndex:[theIndexPath 
indexAtPosition:1]]];
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
    [audioSession setActive:YES error:nil];
    NSLog(@"%d", [self isFirstResponder]);
    
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL 
fileURLWithPath:file]];
    
    [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(exitedFullscreen:) 
name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(playbackFinished:) 
name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
    
    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
        [[self view] addSubview:[moviePlayer view]];
        [moviePlayer setFullscreen:YES animated:YES];
        [moviePlayer play];
    } else {
        [moviePlayer play];
    }
    [fileView deselectRowAtIndexPath:theIndexPath animated:NO];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
    [self resignFirstResponder];
}

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
    NSLog(@"remoteControlReceivedWithEvent: %@", event);
    if (event.type==UIEventTypeRemoteControl) {
        if (event.subtype==UIEventSubtypeRemoteControlPlay) {
            NSLog(@"Play");
        } else if (event.subtype==UIEventSubtypeRemoteControlPause) {
            NSLog(@"Pause");
        } else if (event.subtype==UIEventSubtypeRemoteControlTogglePlayPause) {
            NSLog(@"Play Pause");
        }
    }
}

- (void)exitedFullscreen:(NSNotification *)notification {
    [[moviePlayer view] removeFromSuperview];
    [moviePlayer stop];
    [moviePlayer release];
    moviePlayer = nil;
    [[AVAudioSession sharedInstance] setActive:NO error:nil];
}

- (void)playbackFinished:(NSNotification *)theNotification {
    [[NSNotificationCenter defaultCenter] removeObserver:self 
name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
    [[NSNotificationCenter defaultCenter] removeObserver:self 
name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
    NSNumber *reason = [[theNotification userInfo] 
objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
    if ([reason intValue]!=MPMovieFinishReasonUserExited) {
        [moviePlayer setFullscreen:NO animated:YES];
        [[moviePlayer view] removeFromSuperview];
        [moviePlayer stop];
        [moviePlayer release];
        moviePlayer = nil;
        [[AVAudioSession sharedInstance] setActive:NO error:nil];
    }
    NSLog(@"%d", [self isFirstResponder]);
}

As you can see in the code above, I verified that it was first responder and it 
was, so I know it's not a first responder issue.

Can someone help me get this working?

Thanks
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to