为什么我的ReplayKit游戏记录中没有音频?

时间:2016-04-06 17:11:02

标签: ios swift mpmusicplayercontroller replaykit

我使用MPMusicPlayerController在我的应用程序中播放音频,并使用RPScreenRecorder录制屏幕。我遇到的问题是它只记录屏幕而不是应用程序中的音频。我遇到的另一个问题是,当我按下previewController的取消按钮时,由于某种原因它不会解除视图。我究竟做错了什么?

@IBAction func stopTheRecordingAction(sender: AnyObject) {

    stopTheRecording.hidden = true
    recordButton.hidden = false


    RPScreenRecorder.sharedRecorder().stopRecordingWithHandler { (previewController: RPPreviewViewController?, error: NSError?) -> Void in

        if previewController != nil {

            let alertController = UIAlertController(title: "Recording", message: "Do you wish to discard or view your gameplay recording?", preferredStyle: .Alert)

            let discardAction = UIAlertAction(title: "Discard", style: .Default) { (action: UIAlertAction) in
                RPScreenRecorder.sharedRecorder().discardRecordingWithHandler({ () -> Void in
                    // Executed once recording has successfully been discarded
                })
            }

            let viewAction = UIAlertAction(title: "View", style: .Default, handler: { (action: UIAlertAction) -> Void in
                self.presentViewController(previewController!, animated: true, completion: nil)


            })

            alertController.addAction(discardAction)
            alertController.addAction(viewAction)

            self.presentViewController(alertController, animated: true, completion: nil)

        } else {

            // Handle error
        }
    }
}

@IBAction func recordScreen(sender: AnyObject) {
    recordButton.hidden = true
    stopTheRecording.hidden = false

    if RPScreenRecorder.sharedRecorder().available {
        RPScreenRecorder.sharedRecorder().startRecordingWithMicrophoneEnabled(true, handler: { (error: NSError?) -> Void in
            if error == nil { // Recording has started

            } else {
                // Handle error
            }
        })
    } else {
        // Display UI for recording being unavailable

}

}




   func previewControllerDidFinish(previewController: RPPreviewViewController) {
   previewController.dismissViewControllerAnimated(true, completion: nil)
    print("dismiss")
}

1 个答案:

答案 0 :(得分:0)

好的,我得到了它的工作,但我不得不使用AVAudioPlayer而不是MPMusicPlayerController。由于某种原因,replaykit不会使用MPMedia录制音频。