2016-04-29 16 views
6

私は、アプリでフルスクリーンの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]; 
} 
+0

AVAudioSessionCategoryPlayAndRecordを試しました。 – mkto

+0

これを試してみてくださいhttp://codethink.no-ip.org/wordpress/archives/673 – Imran

答えて

4

は他人オプションと再生と録音でミックスを設定している欠けている唯一のもののように見えますオーディオセッションのカテゴリ。

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil]; 

編集:簡単なテストを設定してください。これはうまくいきます。

+0

ありがとうございます。これにより、アプリ内の多くのバグも修正されました。ほんとうにありがとう。 –

+0

マテオの問題が解決したのを見て嬉しいです!私は14時間以内に+300の賞金を授与させていただきます。 – MCKapur

+0

@MateoEncarnacion私の喜び!私は助けになることができてうれしいです。 – hola

1

_BSMachError: (os/kern) invalid capability (20) _BSMachError: (os/kern) invalid name (15)

の原因は、Appleが「HTTPS」のURLの使用を強制するアプリケーションのトランスポート・セキュリティを導入しているという事実であることができます。従来のURLの場合、info.plistを変更して例外を作成することはできますが、新しいURLにはHTTPSを使用することを強くお勧めします。 「HTTPS:」あなただけにあなたのユーチューブのURLを更新した場合は簡単修正です、あなたの場合は

関連する問題