Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RPBroadcastSampleHandler any method not getting called

I want to implement screen sharing functionality like skype(when app is in background then also it will share screen of iPhone), and for that i am using broadcast extension.

Here its my code in my viewcontroller.swift

    import UIKit
    import ReplayKit
    @available(iOS 12.0, *)
    class ViewController: UIViewController {

        var broadcastPicker: RPSystemBroadcastPickerView?
        var broadcastSession : NSObject?
        override func viewDidLoad() {
            super.viewDidLoad()
            let kPickerFrame = CGRect(x: 100.0, y: 100.0, width: 100.0, height: 100.0)
            broadcastPicker = RPSystemBroadcastPickerView(frame: kPickerFrame)
            broadcastPicker?.backgroundColor = UIColor.green
            broadcastPicker!.preferredExtension = "com.sharescreen.Recoder"
            view.addSubview(broadcastPicker!)

            extensionContext?.loadBroadcastingApplicationInfo(completion: {
            (bundleID, displayName, appIcon) in

            })

        }
   }

and when i click on RPSystemBroadcastPickerView i am getting popup for start broadcast and when i start broadcast any extension method is not calling.

This is my extension class

    class SampleHandler: RPBroadcastSampleHandler {


    var session : VTCompressionSession?
    override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {
        // User has requested to start the broadcast. Setup info from the UI extension can be supplied but optional.

    }

    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:
            // Handle video sample buffer

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

Can you please help me to find out that what i am doing wrong?

like image 901
Govind Rakholiya Avatar asked Jan 10 '20 12:01

Govind Rakholiya


2 Answers

You could also select and run the extension (instead of the iOS target). XCode will then ask you "Choose an app to run" with a list of all apps on your device. Select your app and click "run".

Then your app will be started, but your extension will be debugged (breakpoints will apply and prints will be shown in the output console) after you long press the record/broadcast button in the control view, select your extension and start broadcasting.

like image 187
ggs Avatar answered Oct 29 '22 19:10

ggs


I faced the same issue when I override the method - (void)beginRequestWithExtensionContext:(nonnull NSExtensionContext *)context { [self initScreenBroadcast]; }

I resolved the error by calling super of this method.

- (void)beginRequestWithExtensionContext:(nonnull NSExtensionContext *)context {
[super beginRequestWithExtensionContext:context];
[self initScreenBroadcast];

}

Note: I am not using a Broadcast UI extension with Broadcast upload Extension so my extension has no ui, due to which the method broadcastStartedWithSetupInfo was never called. This is called when the setupUI finishes. Hence I had to get the trigger by overriding beginRequestWithExtensionContext

Hope it helps!

like image 45
SaadurRehman Avatar answered Oct 29 '22 18:10

SaadurRehman