1

我想用 MPMoviePlayerController 在后台播放视频的声音。过去的视频正在运行,但背景声音停止。我想继续声音和背景(在背景中只有声音)。info.plist 的背景模式设置为“音频”

    - (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)Play_Video{
    [[AVAudioSession sharedInstance] setDelegate: self];
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive: YES error: nil];


    self.movieController = [[MPMoviePlayerController alloc] init];

    self.movieController.view.frame = self.view.bounds;
    self.movieController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    self.movieController.backgroundView.backgroundColor = [UIColor clearColor];
    self.movieController.view.hidden = NO;
    self.movieController.controlStyle = MPMovieControlStyleEmbedded;
    [self.view addSubview:self.movieController.view];
    self.movieController.useApplicationAudioSession = NO;

    [UrlBlock VideoURL:url success:^(NSURL *URL) {

        if (self.movieController)
            self.movieController.contentURL = URL;
        else
            self.movieController = [[MPMoviePlayerController alloc] initWithContentURL:URL];

    } failure:^(NSError *error) {
        [self performSelectorOnMainThread:@selector(Alert:) withObject:error waitUntilDone:NO];
    }];


}
4

1 回答 1

0

这可能很明显,也许您只是没有将其粘贴,但是您是否覆盖了该- (BOOL) canBecomeFirstResponder方法?

IE

- (BOOL) canBecomeFirstResponder {
    return YES;
}
于 2012-09-13T20:40:18.127 回答