Use the camera view with GoCoder SDK for iOS

Wowza GoCoder is sunset and should only be used with existing Ultra-Low Latency (ULL) streams until that technology is also sunset.

Learn how to use the WOWZCameraPreview class UI component of the Wowza GoCoder™ SDK for iOS to display a preview of the active camera.

Before you begin

Before adding the functionality below to an app, make sure you've set up the Wowza GoCoder SDK for your project:

  • Request a free license and download the latest version of the SDK.
  • Configure your Xcode project to use the SDK.

See Download and install GoCoder SDK for iOS for detailed instructions.

Display the camera preview

Use the cameraView property in the WowzaGoCoder class to specify the UIViewController-based view for the camera preview. Use the startPreview and stopPreview methods, respectively, to start and stop the camera preview display.

// Demonstrates typical usage within the implementation of a UIViewController-based subclass
- (void) viewDidLoad {
   [super viewDidLoad];

   // ... view initialization code ...

  // Initialize the SDK
  [WowzaGoCoder registerLicenseKey:SDKSampleAppLicenseKey];
  self.goCoder = [WowzaGoCoder sharedInstance];

  // Assign the camera view
  self.goCoder.cameraView = self.view;

  // Start the camera preview
  self.goCoder.cameraPreview = self.goCoder.cameraPreview;
  [self.goCoder.cameraPreview startPreview];

  // ... additional view initialization code ...

Detect the cameras available

The cameras property is an array of WOWZCamera objects that provide access to each of the device's cameras.

// Enable the switch camera button if more than one camera is available
self.switchCameraButton.enabled = self.goCoder.cameraPreview.cameras.count > 1;

Set the active camera

Use the camera property to specify the active camera and the switchCamera method to switch between cameras when multiple cameras are available.

// Set the active camera to the front camera if it is not already active
if ( != WOWZCameraDirectionFront)

Set the preview frame size

Use the config property to set the frame size for the camera preview.

Note: If you specify a frame size that the active camera doesn't support, the closest supported frame size is used.

// Set the camera preview to 720p
WowzaConfig previewConfig = self.goCoderCameraPreview.config;
[previewConfig loadPreset:WOWZFrameSizePreset1280x720];
self.goCoder.cameraPreview.config = previewConfig;

Set the crop and scale behavior

Use the previewGravity property to specify how the camera preview should be displayed when the active frame size or aspect ratio of the camera does not match the view. The following modes are available:

Property Description
WOWZCameraPreviewGravityResizeAspect Scale the camera preview to fit within the screen area. Letterboxing may be applied to maintain its aspect ratio.
WOWZCameraPreviewGravityResizeAspectFill Scale the camera preview to fill the entire screen area. The preview may be cropped to maintain its aspect ratio.
WOWZCameraPreviewGravityResize Stretch the camera preview to fit entirely within the screen area.

Use the following command to set the previewGravity mode.

// Set the cropping mode so that the full frame is displayed, potentially cropped
self.goCoder.cameraPreview.previewGravity = WOWZCameraPreviewGravityResizeAspect;

More resources