IOS9 ReplayKit Video Recording

Source: Internet
Author: User

IOS9 ReplayKit Video Recording

 

IOS9 ReplayKit video recording, the api is very simple, the following is the code, Objective-C is similar, it will not be written.

/// ReplayKitProxy. swift // ReplayKitDemo /// Created by LiuYanghui on 15/12/11. // Copyright? 2015 LiuYanghui. All rights reserved. // import UIKitimport ReplayKitclass ReplayKitProxy: NSObject, RPPreviewViewControllerDelegate {private var rootViewController: UIViewController? Private var previewViewController: RPPreviewViewController? Class var sharedInstance: ReplayKitProxy {struct Static {static var onceToken: dispatch_once_t = 0 static var instance: ReplayKitProxy? = Nil} dispatch_once (& Static. onceToken) {Static. instance = ReplayKitProxy () Static. instance ?. InitData ()} return Static. instance!} Private func initData () {}// start recording video func startRecording () {let recorder = RPScreenRecorder. sharedRecorder () if recorder. available = false {print ("Replaykit is not available") return} if recorder. recording = true {print ("Replaykit is recording") return} recorder. startRecordingWithMicrophoneEnabled (true) {(error)-> Void in if error! = Nil {print (error ?. LocalizedDescription) }}// stop the recording video func stopRecording () {let recorder = RPScreenRecorder. sharedRecorder () if recorder. recording = false {return} recorder. stopRecordingWithHandler {(previewViewController, error)-> Void in if error! = Nil {print (error ?. LocalizedDescription)} else if let viewController = previewViewController {viewController. previewControllerDelegate = self. previewViewController = viewController }}// deletes a recorded video. You must call func discardRecording () {let recorder = RPScreenRecorder after stopRecording. sharedRecorder () if recorder. recording = true {return} recorder. discardRecordingWithHandler {()-> Void in print ("discardRecording co Mplete ") }}// display the video func displayRecordingContent () {rootViewController ?. PresentViewController (self. previewViewController !, Animated: true, completion: {()-> Void in print ("display complete")} // MARK:-delegate func previewControllerDidFinish (previewController: rppreviewviewviewcontroller) {previewController. dismissViewControllerAnimated (true) {()-> Void in }}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.