2017-10-14 13 views
3

に追加オーディオデバイスは、UIImpactFeedbackGeneratorを無効にすると思われるとき。UIImpactFeedbackGeneratorが動作しない<strong>AVCaptureSession</strong>にマイクの音声入力を追加AVCaptureSession

let audioDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio) 
let audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice) 
if self.session.canAddInput(audioDeviceInput) { 
    self.session.addInput(audioDeviceInput) 
} 

オーディオデバイスが削除されると、フィードバックが再開されます。

これは正常な動作ですか?これを回避する方法はありますか?

私が気づいたのは、ビデオモードのカメラアプリで、サムネイルを長押しすると、まだフィードバックが働いているようです。だから、これを回避する方法が必要ですか?

答えて

3

これは意図的な動作のようです。

キャプチャセッションを停止し、ハプティックを再生し、キャプチャセッションを再開することができます。キャプチャセッションを再開するには、キャプチャした最後のフレームのぼやけた静的イメージ。例:

self.session.stopRunning() 
// Play haptic 
UINotificationFeedbackGenerator().notificationOccurred(.warning) 
// Not completely sure if this delay is needed but you might need to wait until the run loop after the haptic plays to resume capture session 
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) 
{ 

    self.session.startRunning() 
} 
関連する問題