【问题标题】:MPMoviePlayerController play backgroundMPMoviePlayerController 播放背景
【发布时间】:2012-09-06 20:40:32
【问题描述】:

我想用 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];
    }];


}

【问题讨论】:

    标签: iphone objective-c ios mpmovieplayercontroller multitasking


    【解决方案1】:

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

    - (BOOL) canBecomeFirstResponder {
        return YES;
    }
    

    【讨论】:

    • 感谢您的回复。我是 Objective-C 编程的新手。添加到调用块,但仍然没有工作。越过锁定的屏幕,声音停止。如果你能帮助我,我将不胜感激。
    • 你不能停止通话,但你可以在通话结束后播放视频或声音
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多