Why is my Screen-Share Preview reversed/mirrored in my iOS App

TokBox iOS Screen-sharing Preview - Why is my Screen-Share preview reversed/mirrored in my iOS App

Customer created a screen-sharing App in iOS based on our example code and then added a preview window to show what is being published.  The view is mirrored horizontally.

Question

  • Why is my iOS Screen-share preview mirrored?
  • Why is my preview mirrored?
  • Why is my preview reversed?

Context

When you create a Screen-share publisher in iOS it uses the current publisher settings.  By default the Camera Position is set to Front and the Front Camera preview is reversed to give a mirrored view in the preview.  It is NOT reversed in the published stream. 

Answer

Before you set your publisher to "screen" you should tell your publisher that your Camera Position is "back" so that the publisher View does not reverse when rendering locally on the device.

Here is the sample code with the additional line highlighted:

 let settings = OTPublisherSettings()
settings.name = UIDevice.current.name
publisher = OTPublisher(delegate: self, settings: settings)
publisher?.cameraPosition = AVCaptureDevice.Position.back;
publisher?.videoType = .screen
publisher?.audioFallbackEnabled = false

capturer = ScreenCapturer(withView: view)
publisher?.videoCapture = capturer

session.publish(publisher!, error: &error)

  

Setting the OTPublisher.cameraPosition corrects the issue with the screen preview being reversed.  If you then append a screen preview to your layout using code similar to that below the preview will not be reversed.

if let publisherView = publisher!.view {
publisherView.frame = CGRect(x: 10,
y: 10,
width: kWidgetWidth,
height: kWidgetHeight)
view.addSubview(publisherView)
}

 For more information please see the following Apple Developer page on AVCaptureDevice.position:

https://developer.apple.com/documentation/avfoundation/avcapturedevice/position

 

 

Have more questions? Submit a request