I have video playing in my application which I don't want to be recorded. What Netflix application do is that they let the audio capture but not the video while screen is being recorded.
Anyone have idea how to implement this feature?
You can listen for a UIScreenCapturedDidChange
notification.
NotificationCenter.default.addObserver(self, selector: #selector(screenCaptureChanged), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)
This is called when iOS 11 screen recording begins and ends. When the user is recording the screen, you can modify the UI to block any content that you don't want recorded.
This notification is fired when UIScreen
's isCaptured
property changes. You can also inspect this property yourself:
UIScreen.main.isCaptured
I believe, Netflix takes advantage of the "FairPlay Streaming" technology provided by Apple. According to Apple Documentation
If your application uses FairPlay Streaming (FPS) your video content will automatically not be captured by the iOS 11 screen recording feature or QuickTime Player on macOS. The portion of your application that is playing the content will be blacked out.
Note: FairPlay Streaming will only provide protection for the video portion of your content. To prevent capture of the audio portion you should still use the UIScreen APIs discussed in this document to provide an appropriate message to the user if screen capture begins.
One can get an in-depth understanding of FPS from the link below :
https://developer.apple.com/streaming/fps/
Any application can incorporate FPS in order to achieve same results as Netflix.
I create a black view and add it at the top of UIWindow. Then, in view controller of PlayerVideo, create the observer
NotificationCenter.default.addObserver(self, selector: #selector(screenCaptureChanged), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)
Then, in screenCaptureChanged
:
(void) screenCaptureChanged {
if (@available(iOS 11.0, *)) {
BOOL isCaptured = [[UIScreen mainScreen] isCaptured];
if (isCaptured) {
self.blackView.hidden = false;
}
else {
self.blackView.hidden = true;
}
}
}
This solution will block the PlayerVideo when user is recording. However, I would like to create something like Netflix did. I want to let users do whatever they want while watching movie. If they are recording, they can continue watching video without black view. However, when they stop recording, the video will be save with black view. I'm still figuring out how Netflix did like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With