私は、アプリでフルスクリーンのYouTubeビデオを表示するのにWKWebView
を使用しています.YouTubeでビデオをブラウズして再生している間は、オーディオとビデオをバックグラウンドで記録するAVCaptureSessionを使用しています。キャプチャセッションは、ボタンが押されると開始されます。ただし、録画中は、YouTubeビデオが選択されてフルスクリーンで再生されると、録画の終了を処理するデリゲートメソッドが呼び出されるため、録画が予期せず終了します。Webビューでビデオを再生すると、予期せずに背景ビデオ録画が終了しますか?
この問題を解決する方法を教えてもらえますか?これが完全に関連しているかどうかは不明ですが、_BSMachError: (os/kern) invalid capability (20) _BSMachError: (os/kern) invalid name (15) and Unable to simultaneously satisfy constraints.
などのエラーメッセージが表示されますが、後者の場合は別のAutoLayoutの問題を参照しているようです。どんな助けでも大歓迎です。
また、WKWebView
の代わりにUIWebView
を使用しようとしました。 UIWebView
を使用すると、ビデオの録画中にYouTubeビデオが再生されなくなるという問題があります。それはちょうど開き、黒い画面の0:00にとどまります。
録音を最初に開始するときに押すボタンです。
- (void) buttonClickedStart:(UIButton*)sender //button to start/end recording {
if (!WeAreRecording) {
[self setupVideoCapture];
//----- START RECORDING -----
WeAreRecording = YES;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil];
//Create temporary URL to record the video to for later viewing
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = [paths objectAtIndex:0];
NSString *outputPath = [[NSString alloc] initWithFormat:@"%@", [basePath stringByAppendingPathComponent:@"output.mp4"]];
if ([[NSFileManager defaultManager] isDeletableFileAtPath:outputPath])
[[NSFileManager defaultManager] removeItemAtPath:outputPath error:NULL];
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];
[MovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
self.outputURLs = outputURL;
}
else {
//----- STOP RECORDING -----
WeAreRecording = NO;
[MovieFileOutput stopRecording];
}
}
ボタンを押したときに呼び出されるメソッドです。 CaptureSession
というキャプチャセッションを設定して開始します。
- (void)setupVideoCapture {
// Sets up recording capture session
CaptureSession = [[AVCaptureSession alloc] init];
// Add video input to capture session
AVCaptureDevice *VideoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (VideoDevice) {
NSError *error;
VideoInputDevice = [[AVCaptureDeviceInput alloc] initWithDevice:[self CameraWithPosition:AVCaptureDevicePositionFront] error:&error];
if (!error) {
if ([CaptureSession canAddInput:VideoInputDevice])
[CaptureSession addInput:VideoInputDevice];
}
}
// Add audio input to capture session
AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
NSError *error = nil;
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];
if (audioInput) {
[CaptureSession addInput:audioInput];
}
// Add movie file output to the capture session
MovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
[MovieFileOutput setMovieFragmentInterval:kCMTimeInvalid];
if ([CaptureSession canAddOutput:MovieFileOutput])
[CaptureSession addOutput:MovieFileOutput];
// Set the output properties (you don't really need to see this code)
[self CameraSetOutputProperties]; // (We call a method as it also has to be done after changing camera)
[CaptureSession setSessionPreset:AVCaptureSessionPresetMedium];
//----- START THE CAPTURE SESSION RUNNING -----
[CaptureSession startRunning];
}
これは、WKWebView
が宣言されセットアップされている場所です。
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Add recording button
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
CGRect rect = CGRectMake(0, 0, screenSize.width, 337);
UIButton *start = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[start addTarget:self action:@selector(buttonClickedStart:) forControlEvents:UIControlEventTouchUpInside];
[start setFrame:CGRectMake(30, 338, 35, 35)];
[start setTitle:@"" forState:UIControlStateNormal];
[start setExclusiveTouch:YES];
[start setBackgroundImage:[UIImage imageNamed:@"start.png"] forState:UIControlStateNormal];
[self.view addSubview:start];
// Add web view
webView = [[WKWebView alloc] initWithFrame:rect];
[self.view addSubview:webView];
NSString *webSite = @"http://www.youtube.com";
NSURL *url = [NSURL URLWithString:webSite];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
webView.navigationDelegate = self;
webView.UIDelegate = self;
[webView loadRequest:request]; // Load up Youtube
[self.view addSubview:webView];
}
AVAudioSessionCategoryPlayAndRecordを試しました。 – mkto
これを試してみてくださいhttp://codethink.no-ip.org/wordpress/archives/673 – Imran