Screen recording when my iOS app is in background with ReplayKit
Asked Answered
S

1

4

I have tried Broadcast Extension. I have added that extension via target. But, I don't know how to record when my app is in background.

Two ways I am trying to record:

Via Control center: I can see my app’s target name, after selecting that name, then I start to record by clicking Start Broadcast, next by clicking Stop Record, but my video not getting stored either in Camera Roll or in my app. Ref Link: ReplayKit's RPSystemBroadcastPickerView not showing preferredExtension

Via my app: Once press Start button, recording get started, I am trying to record background from my app by clicking home button, obviously recording has been stopped. Ref Link: https://medium.com/@giridharvc7/replaykit-screen-recording-8ee9a61dd762.

Squeak answered 1/2, 2019 at 18:38 Comment(5)
"Via my app" - as far as I know, this approach won't work. You can't start recording from your app, press the home button, and expect recording to continue. "Via control center" - you will have to actually show some code to see where the problem is.Preview
RPSystemBroadcastPickerView, this giving "press the home button, and expect recording to continue". @Preview . But, I cannot detect when my recording get finish via my app.Squeak
BroadcastExtension will store saved file to its own folder, you need to manually copy the file to app's document folder, then save the file to Gallery.Conoscenti
Yes. I understood the concept behind BroadcastExtension . Once broadcast completed, asset.finishWriting{} is not called. Do u know how to make this Completion handler to invoke automatically? But, while we recording, if we face any error in processSampleBuffer , asset.finishWriting{} its get called automatically. But, record is completed without any error, this function not getting called.Squeak
I have the same issue with my code so I put sleep function for 2 seconds which gives my completion handler to create the file in the end.Hu
M
5

There is no "direct" way to store video in your app while it is in the background. ReplayKit version 2 allows you to get video sample buffer pieces in the app extensions that calls "Broadcast Upload Extension". When you say "Via Control center" it means that you start broadcast (not recording), and at the same time iOS finds your app-extension (not your application) and launch it, then begins send video sample buffers to the extension. On this step you need to decide what to do with these buffers.

I can propose two solutions for you:

  • you can try transfer buffers to the server (and download video when main application will be launched)
  • you can try save buffers to the file using App Groups (to share this data with the main application), you can find example here.

But you need to know that broadcast extension has been designed for buffer transferring, not to store or re rendering or compress or recode buffers. Extension has a lot of limitations based on CPU time and Memory usage (±50 MB), you can try to do anything there but if it is "heavy" operation iOS will close the extension.

Multiparous answered 4/2, 2019 at 10:20 Comment(9)
Thanks a lot. Now I am having clear idea. I have added Broadcast Upload Extension to my app. Now, broadcast started "via control center", but no action happening in "class SampleHandler: RPBroadcastSampleHandler" and "class BroadcastSetupViewController: UIViewController" . How to do this?Squeak
For your purpose you need only SampleHandler class. Add print("debug-message") line to broadcastStarted and processSampleBuffer functions to see that extension works, then manually start broadcast via control center. To debug it, you need to change build target to upload extension target and run the project. @SqueakMultiparous
Yes u r right. I need only SampleHandler class. I have tried with UserDefault logic to check how my extensions work. Its working fine. My next step is, how to save this video in camera roll. Thanks @Bws Sluk.Squeak
#46903618 , from here, I am trying to save recorded video in Camera Roll. But, that is not working. I am having content in that recorded URL. I have checked that by converting to Data. Now, I am calling,PHPhotoLibrary.shared().performChanges({ , then Completion handler, neither success nor failure is triggered, . Can u help me on this.??Squeak
@Squeak Hi, I have created broadcast upload extension and added print messages as said. but I'm not getting any logs neither my methods are getting called. changing the target is asking to select an app to run. how you achieved this?Accordingly
You will not get any logs. You have to save ur logs as String in UserDefaults. @KrutikaSonawalaSqueak
@Squeak Ok. now what should be the next step? I have set my server. Now how will I get this data sent on server? webRTC does this?Accordingly
V can't discuss full process here. You can search some live examples like MobCrushSqueak
I am able to record Video and tried saving the audio also. but audio is not recorded. When i try the same with RPScreenRecorder i can hear audio also along with video. Any help please.Hammonds

© 2022 - 2024 — McMap. All rights reserved.