我在我的应用程序中使用 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)
}