RPPreviewViewController disables audio after playback

451 views Asked by At

I'm using replaykit in my app, and after the user has done a recording I provide a button to "share" the video. I present the RPPreviewViewController, and if I click play in the video, when I go back to the app, audio doesn't work. It only works again once I've gone back to a previous viewController and back into the one with recording.

My app is a music composition app, so audio is very important. I've even tried reseting the AVAudioSession category after the playback view dismisses like so:

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)
}
2

There are 2 answers

2
Jer On

Not sure if this is any help, but just found that issue with ours, where we use OalPlayback for sound effects. Before showing the preview controller I now release the Oal object and after dismissing the preview I make a new one.

0
mad pig On

I use ObjectAL and found this issue also. I was able to solve it by using this command:

OALAudioSession.sharedInstance().forceEndInterruption()

Seems replayKit is not ending an interrupt.