1

アプリで replaykit を使用しています。ユーザーが録画を行った後、ビデオを「共有」するためのボタンを提供します。を提示しRPPreviewViewController、ビデオで再生をクリックすると、アプリに戻ると音声が機能しません。以前に戻って、記録のあるものに戻った場合にのみ、再び機能しviewControllerます。

私のアプリは作曲アプリなので、オーディオは非常に重要です。AVAudioSession再生ビューが次のように閉じた後、カテゴリをリセットしようとしました:

func showPreview() {
    if let unwrappedPreview = self.preview {
        unwrappedPreview.previewControllerDelegate = self
        self.present(unwrappedPreview, animated: true, completion: nil)
    } else {
        let alert = UIAlertController(title: "No recordings to share", message: "By hitting the play or record button you can record a video of your composition to share with others. Once you hit stop, the recording will be saved and ready to share.", preferredStyle: .alert)
        let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        alert.addAction(okAction)
        self.present(alert, animated: true, completion: nil)
    }
}

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
    let audioSession = AVAudioSession.sharedInstance()
    try! audioSession.setCategory(AVAudioSessionCategoryPlayback)
    dismiss(animated: true)
}
4

2 に答える 2