5

iPhoneからビデオを録画するアプリを作成しました。正常に動作しますが、大きな問題が 1 つあります。AVCaptureSession が実行を開始し、ユーザーがライブラリ (iPod) からオーディオを再生しようとすると。このアクションにより、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];
4

3 に答える 3

1

これは私のために働いた:

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

}

于 2012-12-11T01:24:21.403 に答える
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});
于 2012-08-01T08:14:43.263 に答える
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];
于 2011-11-14T16:33:18.700 に答える