Step by Step Tutorial

 1. Create a new application project

a. Open Xcode and select the option to create a new project from the File menu.

b. On the template selection dialog, select Single View Application .

c. On the project options dialog, ensure you have specified the options such that the Bundle Identifier field matches the one used to license the SDK.

d. Follow the instructions on the installation page to add the SDK library to the project.

a. Open Android Studio and select the option to create a new project.

b. On the New Project dialog, select Edit next to the the Package Name field

c. Enter the application package name that was used to license the GoCoder SDK.

d. In the Activity type selection dialog, select Empty Activity.

e. Add the following permissions to the app's AndroidManifest.xml file:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

f. Follow the instructions on the installation page to add the SDK library to the project.


 2. Update the U/I layout

a. Open Main.storyboard and add a button to the View element.

b. Change the title of the button to Broadcast.

c. Add a referencing outlet named broadcastButton from the button to ViewController.m:

@interface ViewController ()

// Referencing outlet for the broadcast button
@property (weak, nonatomic) IBOutlet UIButton *broadcastButton;

@end

Edit the layout definition file for the main application activity (e.g. project_root/app/src/main/res/layout/activity_main.xml) and add a view for the camera preview and a broadcast button like so:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:wowza="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mycompany.myapplication.MainActivity">

    <!-- The camera preview display -->
    <com.wowza.gocoder.sdk.api.devices.WZCameraView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/camera_preview"
        wowza:scaleMode="crop"
        wowza:defaultCamera="back"
        wowza:frameSizePreset="frameSize1280x720"/>

    <!-- The broadcast button -->
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Broadcast"
        android:id="@+id/broadcast_button"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

 3. Update the primary app class

Add properties for the primary GoCoder SDK components to the implementation of the ViewController class in ViewController.m:

// Implements the WZStatusCallback protocol
@interface ViewController ()

// The top level GoCoder API interface
@property (nonatomic, strong) WowzaGoCoder *goCoder;

// The GoCoder SDK camera view
@property (nonatomic, strong) WZCameraPreview *goCoderCameraPreview;

Add member variables for the primary GoCoder SDK components to the primary activity class (e.g. project_root/app/src/main/java/MainActivity.java):

public class MainActivity extends Activity {

    // The top level GoCoder API interface
    private WowzaGoCoder goCoder;

    // The GoCoder SDK camera view
    private WZCameraView goCoderCameraView;

 4. Initialize the SDK

The first step is to register the SDK license key with [WowzaGoCoder registerLicenseKey] and then initialize the SDK itself by calling WowzaGoCoder.init. Add the following to the viewDidLoad method of the ViewController class.

// Register the GoCoder SDK license key
NSError *goCoderLicensingError = [WowzaGoCoder registerLicenseKey:@"GSDK-XXXX-XXXX-XXXX-XXXX-XXXX"];
if (goCoderLicensingError != nil) {
    // Log license key registration failure
    NSLog(@"%@", [goCoderLicensingError localizedDescription]);
} else {
    // Initialize the GoCoder SDK
    self.goCoder = [WowzaGoCoder sharedInstance];
}

The first step is to initialize the SDK by calling WowzaGoCoder.init and supplying the Android application context and license key. Add the code below to the bottom of the onCreate() method in the MainActivity class, replacing the string "GSDK-XXXX-XXXX-XXXX-XXXX-XXXX" with your SDK license key:

// Initialize the GoCoder SDK
this.goCoder = WowzaGoCoder.init(getApplicationContext(), "GSDK-XXXX-XXXX-XXXX-XXXX-XXXX");

if (this.goCoder == null) {
    // If initialization failed, retrieve the last error and display it
    WZError goCoderInitError = WowzaGoCoder.getLastError();
    Toast.makeText(this,
            "GoCoder SDK error: " + goCoderInitError.getErrorDescription(),
            Toast.LENGTH_LONG).show();
    return;
}

 5. Specify the camera view

Add the following to the bottom of the viewDidLoad method to associate the U/I view with the SDK's camera preview:

if (self.goCoder != nil) {
     // Associate the U/I view with the SDK camera preview
     self.goCoder.cameraView = self.view;
}

Associate the view from the layout definition with the SDK's camera preview:

// Set the camera view
this.goCoderCameraView = (WZCameraView) findViewById(R.id.camera_preview);
this.goCoder.setCameraView(this.goCoderCameraView);

 6. Specify the broadcast settings

// Get a copy of the active config
WowzaConfig broadcastConfig = self.goCoder.config;

// Set the defaults for 720p video
[broadcastConfig loadPreset:WZFrameSizePreset1280x720];
// Set the address for the Wowza Streaming Engine server or Wowza Cloud
broadcastConfig.hostAddress = @"live.someserver.net";
// Set the name of the stream
broadcastConfig.streamName = @"conventionCoverage";

// Update the active config
self.goCoder.config = broadcastConfig;

Add the code below to the onCreate() method in the MainActivity class, after the SDK has been initialized, replacing the strings "live.someserver.net" and "someStreamName" with appropriate values for your environment:

// Specify the broadcast configuration parameters
WowzaConfig broadcastConfig = this.goCoder.getConfig();

// Update the active config to the defaults for 720p video
broadcastConfig.set(WZMediaConfig.FRAME_SIZE_1920x1080);
// Set the address for the Wowza Streaming Engine server or Wowza Cloud
broadcastConfig.setHostAddress("live.someserver.net");
// Set the name of the stream
broadcastConfig.setStreamName("someStreamName");

// Update the active config
this.goCoder.setConfig(broadcastConfig);

 7. Start the camera preview

Update the viewDidLoad method to start the camera preview like so:

if (self.goCoder != nil) {
     // Associate the U/I view with the SDK camera preview
     self.goCoder.cameraView = self.view;

     // Start the camera preview
     [self.goCoderCameraPreview startPreview];
}

Add an onResume() method to the activity class where we will turn on the camera preview when the application is brought to the foreground:

@Override
protected void onResume() {
    super.onResume();

    if (this.goCoder != null) {
        this.goCoder.startCameraPreview();

        WZCamera activeCamera = this.goCoderCameraView.getCamera();
        if (activeCamera != null && activeCamera.hasCapability(WZCamera.FOCUS_MODE_CONTINUOUS)) {
            activeCamera.setFocusMode(WZCamera.FOCUS_MODE_CONTINUOUS);
        }
    }
}

 8. Enable the broadcast button

Add the following method to the ViewController class:

- (IBAction)broadcastButtonTapped:(UIButton *)button
{
    // Ensure the minimum set of configuration settings have been specified necessary to
    // initiate a broadcast streaming session
    NSError *configValidationError = [self.goCoder.config validateForBroadcast];

    if (configValidationError != nil) {
        UIAlertView *alertDialog =
            [[UIAlertView alloc] initWithTitle:@"Incomplete Streaming Settings"
                                  message:goCoderStatus.description
                                 delegate:nil
                        cancelButtonTitle:@"OK"
                        otherButtonTitles:nil];
        [alertDialog show];
    } else if (self.goCoder.status.state != WZStateRunning) {
        // Start streaming
        [self.goCoder startStreaming:self];
    }
    else {
        // Stop the broadcast that is currently running
        [self.goCoder endStreaming:self];
    }    
}

Then add the following code to the bottom of the viewDidLoad method:

[self.broadcastButton addTarget:self action:@selector(broadcastButtonTapped:)
    forControlEvents:UIControlEventTouchUpInside];

a. Update the class definition for the primary activity class to include the View.OnClickListener interface:

// Implements the View.OnClickListener interfaces
public class MainActivity extends Activity
        implements View.OnClickListener {

b. Add the event handler below that will be invoked when the broadcast button is pressed:

 @Override
 public void onClick(View view) {
     // Ensure the minimum set of configuration settings have been specified necessary to
     // initiate a broadcast streaming session
     WZStreamingError configValidationError = sGoCoder.getConfig().validateForBroadcast();

     if (configValidationError != null) {
         Toast.makeText(this, configValidationError.getErrorDescription(), Toast.LENGTH_LONG).show();
     } else if (this.goCoder.isStreaming()) {
         // Stop the broadcast that is currently running
         this.goCoder.endStreaming(this);
         }
     } else {
         // Start streaming
         this.goCoder.startStreaming(this);
     }
 }

c. Add the lines below to the bottom of the onCreate() method to associate the event handler with the button's click event:

final Button broadcastButton = (Button) findViewById(R.id.broadcast_button);
broadcastButton.setOnClickListener(this);

 9. Add broadcast monitoring callbacks

a. Update the interface definition for the ViewController class to include the WZStatusCallback protocol:

// Implements the WZStatusCallback protocol
@interface ViewController () <WZStatusCallback>

b. Add the methods defined by the WZStatusCallback protocol for monitoring status updates and errors during a live streaming broadcast.


- (void) onSuccess:(WZStatus *) goCoderStatus {
    // A successful status transition has been reported by the GoCoder SDK
    NSString *statusMessage = nil;

    switch (goCoderStatus.state) {
        case WZStateIdle:
            statusMessage = @"The broadcast is stopped";
            break;

        case WZStateStarting:
            statusMessage = @"Broadcast initialization";
            break;

        case WZStateRunning:
            statusMessage = @"Streaming is active";
            break;

        case WZStateStopping:
            statusMessage = @"Broadcast shutting down";
            break;
    }

    if (statusMessage != nil)
        NSLog(@"Broadcast status: %@", statusMessage);
}

- (void) onError:(WZStatus *) goCoderStatus {
    // If an error is reported by the GoCoder SDK, display an alert dialog
    // containing the error details using the U/I thread
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertView *alertDialog =
            [[UIAlertView alloc] initWithTitle:@"Streaming Error"
                                  message:goCoderStatus.description
                                 delegate:nil
                        cancelButtonTitle:@"OK"
                        otherButtonTitles:nil];
        [alertDialog show];
    });
}

a. Update the class definition for the primary activity class to include the WZStatusCallback interface:

// Implements the WZStatusCallback and View.OnClickListener interfaces
public class MainActivity extends Activity
        implements WZStatusCallback, View.OnClickListener {

b. Add the methods defined by the WZStatusCallback interface for monitoring status updates and errors during a live streaming broadcast.

@Override
public void onSuccess(final WZStatus goCoderStatus) {
    // A successful status transition has been reported by the GoCoder SDK
    final StringBuffer statusMessage = new StringBuffer("Broadcast status: ");

    switch (goCoderStatus.getState()) {
        case WZState.STARTING:
            statusMessage.append("Broadcast initialization");
            break;

        case WZState.READY:
            statusMessage.append("Ready to begin streaming");
            break;

        case WZState.RUNNING:
            statusMessage.append("Streaming is active");
            break;

        case WZState.STOPPING:
            statusMessage.append("Broadcast shutting down");
            break;

        case WZState.IDLE:
            statusMessage.append("The broadcast is stopped");
            break;

        default:
            return;
    }

    // Display the status message using the U/I thread
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(MainActivity.this, statusMessage, Toast.LENGTH_LONG).show();
        }
    });
}

@Override
public void onError(final WZStatus goCoderStatus) {
    // If an error is reported by the GoCoder SDK, display a message
    // containing the error details using the U/I thread
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(MainActivity.this,
                    "Streaming error: " + goCoderStatus.getLastError().getErrorDescription(),
                    Toast.LENGTH_LONG).show();
        }
    });
}

10. Build and deploy

At this stage you are ready to build and deploy your application. Choose Run from the Xcode Product menu.

At this stage you are ready to build and deploy your application. Choose Run or Debug from the Android Studio Run menu and select a device for deployment.


Where To Go Next

The additional information listed below is available using the menu displayed above:

Installation Information Information about installing the GoCoder SDK and using it within your mobile app projects
Developer Guides In depth information for common GoCoder SDK-related tasks and topics
API Reference Detailed GoCoder SDK API reference docs for each platform
FAQ Common GoCoder SDK-related questions
Release Notes Information related to each of the GoCoder SDK releases