Screen Share Preview Reversed or Mirrored in iOS App

Symptom

After creating a screen-sharing App in iOS and adding a preview window to show what is being published, the preview is mirrored horizontally.

Applies To

  • iOS App
  • Screen Sharing

Resolution

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

Cause

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.

Additional Information

For more information, see the Apple Developer page on AVCaptureDevice.position.

Have more questions? Submit a request