ReplayKit Screen detection click

28 views Asked by At

How do I know if the user's finger is in or off the screen when I'm recording the screen?

I tried using RunLoop and touches in SampleHandler to start checking whether a finger was on the screen, but nothing worked。

What I want is that the screen has stopped sliding, maybe there is another way to achieve this effect?

import ReplayKit import AVKit import UIKit import Foundation import AssetsLibrary

class SampleHandler2: RPBroadcastSampleHandler {

let recorder  = RPScreenRecorder.shared()
//    RPPreviewViewController
let ggroupId: String = "group.com.aaa.demo.demo2"
var timer: Timer?

// open override func touchesBegan(_ touches: Set, with event: UIEvent?) { // } // // open override func touchesEnded(_ touches: Set, with event: UIEvent?) { // }

func getTouch() {
    print("1")
    timer = Timer(timeInterval: 2.0, target: UIScreen.main.self, selector: #selector(runLoopAction), userInfo: nil, repeats: true)
    RunLoop.current.add(timer!, forMode: .tracking)
}

@objc func runLoopAction() {
    NSLog("=== run ===")
}


override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {
    getTouch()
}


override func broadcastPaused() {
    // User has requested to pause the broadcast. Samples will stop being delivered.
}



override func broadcastResumed() {
    // User has requested to resume the broadcast. Samples delivery will resume.
}

override func broadcastFinished() {
    // User has requested to finish the broadcast.
}

override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
    switch sampleBufferType {
    case RPSampleBufferType.video:
        
        break
    case RPSampleBufferType.audioApp:
        // Handle audio sample buffer for app audio
        break
    case RPSampleBufferType.audioMic:
        // Handle audio sample buffer for mic audio
        break
    @unknown default:
        // Handle other sample buffer types
        fatalError("Unknown type of sample buffer")
    }
}

}

0

There are 0 answers