2011-01-17 7 views
5

iPhoneからビデオを録画するアプリを作成しました。それは正常に動作しますが、大きな問題が1つあります。 AVCaptureSessionが起動し、ユーザーが自分のライブラリ(iPod)からオーディオを再生しようとしたとき。 このアクションにより、AVCaptureSessionは終了します。 ユーザーがオーディオを再生したり、この問題を解決しようとするのを防ぐことができますか?オーディオでAVCaptureSessionが終了する


これは私のコードです:

videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];   
audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]; 

AVCaptureDeviceInput *videoDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:videoDevice error:nil]; 
AVCaptureDeviceInput *audioDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil]; 

movieFileOutput = [[AVCaptureMovieFileOutput alloc] init]; 

captureSession = [[AVCaptureSession alloc] init]; 

[captureSession beginConfiguration]; 
[captureSession setSessionPreset:AVCaptureSessionPresetHigh]; 
[captureSession addInput:videoDeviceInput]; 
[captureSession addInput:audioDeviceInput]; 
[captureSession addOutput:movieFileOutput]; 
[captureSession commitConfiguration]; 

[captureSession startRunning]; 
+0

解決方法はありますか? – Sandy

+0

@anistarのソリューションを見つけたことがありますか? –

+0

Unfortunatelly私は同じ問題 - 任意のアイデアにぶつかった? – nixau

答えて

0

あなたがNSNotificationCenterを使用する必要があります。下記のコードを使用して(他にもいくつかの便利な方法が含まれています)、キャプチャ中断を処理する方法を書いてください(AVCaptureSessionWasInterruptedNotification)。私はそれが助けて欲しい

NSNotificationCenter *notify = [NSNotificationCenter defaultCenter]; 
[notify addObserver: self selector: @selector(onVideoError:) name: AVCaptureSessionRuntimeErrorNotification object: captureSession]; 
[notify addObserver: self selector: @selector(onVideoInterrupted:) name: AVCaptureSessionWasInterruptedNotification object: captureSession]; 
[notify addObserver: self selector: @selector(onVideoEnded:) name: AVCaptureSessionInterruptionEndedNotification object: captureSession]; 
[notify addObserver: self selector: @selector(onVideoDidStopRunning:) name: AVCaptureSessionDidStopRunningNotification object: captureSession]; 
[notify addObserver: self selector: @selector(onVideoStart:) name: AVCaptureSessionDidStartRunningNotification object: captureSession]; 
+1

しかし、中断しても動作を停止しないようにするには、どのようなことをやめてください。 – Alper

0

オーディオセッションを乱用してみてください!

ここにあなたが何ができるかについて簡単な推測だが、私は特にiPodにこれを試していない:

OSStatus status = noErr; 
status |= AudioSessionInitialize(CFRunLoopGetMain(), kCFRunLoopCommonModes, PVAudioSessionInterruptionListener, NULL); 

    status |= AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(UInt32), &(UInt32){kAudioSessionCategory_PlayAndRecord}); 

    status |= AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, 
             sizeof(UInt32), 
             &(UInt32){true}); 

    status |= AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck, 
             sizeof(UInt32), 
             &(UInt32){false}); 

status |= AudioSessionSetActive(YES); 

if (status != noErr) { 
    NSLog(@"ERROR: There was an error in setting the audio session"); 
} 

私も周囲の音をオーディオカテゴリにいくつかの幸運を持っていた(でも、それにもかかわらず

status |= AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(UInt32), &(UInt32){kAudioSessionCategory_AmbientSound}); 
1

これは私のために働いた:エラーを与え、映像を記録している間)オーディオを再生できるように思わ

- (void)setupAudio { 
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; 
    UInt32 doSetProperty = 1; 
    AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty); 
    [[AVAudioSession sharedInstance] setActive: YES error: nil]; 

}

+0

これをあなたのavcapturesessionにどのように追加しましたか?より多くのコードを提供できますか? –

+0

申し訳ありませんが、私はこれを見なければならなかったので何年も経ちました。 – micahp

関連する問題