1
我想用MPMoviePlayerController在后台播放视频的声音。视频正在运行,但背景音停止。我想继续声音和背景(只有背景声音)。 info.plist中有设置为“音频”MPMoviePlayerController播放背景
- (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];
}];
}
谢谢您的答复。我还不熟悉Objective-C编程。添加到调用该块,但仍然没有工作。经过锁定的屏幕,声音停止。如果你能帮助我,我会很感激。 – user1669335
您无法停止通话,但可以在通话结束后播放视频或声音 – GhostRider