https://www.wowza.com/docs/how-to-build-a-basic-app-with-gocoder-sdk-for-android
Followed this. I ran it on my avd and it says, “The license key specified is invalid.” Okay I literally copy and pasted the license key from my email into the method. OKAY ALSO IF I PASTE CODE I CANNOT CLICK TO THE BOTTOM OF THE CODE AND CONTINUE TYPING. I AM STUCK IN THE CODE EDITOR.
WowzaGoCoder goCoder = WowzaGoCoder.init(this, "EDEV4-pCZ7p-r7eB9-FTXUb-EANnZ-XxDpK-**********");
package com.example.hu.myapplication;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.wowza.gocoder.sdk.api.WowzaGoCoder;
import com.wowza.gocoder.sdk.api.broadcast.WOWZBroadcast;
import com.wowza.gocoder.sdk.api.broadcast.WOWZBroadcastAPI;
import com.wowza.gocoder.sdk.api.broadcast.WOWZBroadcastConfig;
import com.wowza.gocoder.sdk.api.configuration.WOWZMediaConfig;
import com.wowza.gocoder.sdk.api.devices.WOWZAudioDevice;
import com.wowza.gocoder.sdk.api.devices.WOWZCamera;
import com.wowza.gocoder.sdk.api.devices.WOWZCameraView;
import com.wowza.gocoder.sdk.api.errors.WOWZError;
import com.wowza.gocoder.sdk.api.errors.WOWZStreamingError;
import com.wowza.gocoder.sdk.api.geometry.WOWZSize;
import com.wowza.gocoder.sdk.api.status.WOWZState;
import com.wowza.gocoder.sdk.api.status.WOWZStatus;
import com.wowza.gocoder.sdk.api.status.WOWZStatusCallback;
import static com.wowza.gocoder.sdk.api.WowzaGoCoder.hasPermissions;
public class MainActivity extends AppCompatActivity implements WOWZStatusCallback, View.OnClickListener {
// The top-level GoCoder API interfaceprivate WowzaGoCoder goCoder;
// The GoCoder SDK camera viewprivate WOWZCameraView goCoderCameraView;
// The GoCoder SDK audio deviceprivate WOWZAudioDevice goCoderAudioDevice;
// The GoCoder SDK broadcasterprivate WOWZBroadcast goCoderBroadcaster;
// The broadcast configuration settingsprivate WOWZBroadcastConfig goCoderBroadcastConfig;
// Properties needed for Android 6+ permissions handlingprivate static final int PERMISSIONS_REQUEST_CODE = 0x1;
private boolean mPermissionsGranted = true;
private String[] mRequiredPermissions = new String[]{
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO};
@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WowzaGoCoder goCoder = WowzaGoCoder.init(this, "EDEV4-pCZ7p-r7eB9-FTXUb-EANnZ-XxDpK-6ZwCeph7YUZ");
if (goCoder == null) {
// If initialization failed, retrieve the last error and display itWOWZError goCoderInitError = WowzaGoCoder.getLastError();
Toast.makeText(this,
"GoCoder SDK error: " + goCoderInitError.getErrorDescription(),
Toast.LENGTH_LONG).show();
return;
}
// Associate the WOWZCameraView defined in the U/I layout with the corresponding class membergoCoderCameraView = (WOWZCameraView) findViewById(R.id.camera_preview);
// Create an audio device instance for capturing and broadcasting audiogoCoderAudioDevice = new WOWZAudioDevice();
// Create a broadcaster instancegoCoderBroadcaster = new WOWZBroadcast();
// Create a configuration instance for the broadcastergoCoderBroadcastConfig = new WOWZBroadcastConfig(WOWZMediaConfig.FRAME_SIZE_1920x1080);
// Set the connection properties for the target Wowza Streaming Engine server or Wowza Streaming Cloud live streamgoCoderBroadcastConfig.setHostAddress("rtsp://d41a1f.entrypoint.cloud.wowza.com/app-1da1");
goCoderBroadcastConfig.setPortNumber(1935);
goCoderBroadcastConfig.setApplicationName("8e0117a7");
goCoderBroadcastConfig.setStreamName("myStream");
// Designate the camera preview as the video sourcegoCoderBroadcastConfig.setVideoBroadcaster(goCoderCameraView);
// Designate the audio device as the audio broadcastergoCoderBroadcastConfig.setAudioBroadcaster(goCoderAudioDevice);
/*WOWZBroadcastConfig wowzBroadcastConfig; //wowzBroadcastConfig.setVideoBroadcaster(WOWZBroadcastAPI.VideoBroadcaster); // Assign the camera view WOWZCameraView goCoderCameraView = (WOWZCameraView) findViewById(R.id.cameraPreview); goCoder.setCameraView(goCoderCameraView); goCoder.startCameraPreview();// Start the camera preview goCoderCameraView.startPreview(); int numCameras = WOWZCamera.getNumberOfDeviceCameras(this); // Set the active camera to the front camera if it's not active if (!goCoderCameraView.getCamera().isFront()) goCoderCameraView.switchCamera(); // Set the camera preview to 720p WOWZSize actualFrameSize = goCoderCameraView.setFrameSize(new WOWZSize(1280, 720)); // Set the cropping mode so that the full frame is displayed, potentially cropped goCoderCameraView.setScaleMode(WOWZMediaConfig.FILL_VIEW);*/Log.i("WowzaSDKVersion: ", goCoder.SDK_VERSION);
Button broadcastButton = (Button) findViewById(R.id.broadcast_button);
broadcastButton.setOnClickListener(this);
}
@Overridepublic void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
if (rootView != null)
rootView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_FULLSCREEN| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
@Overrideprotected void onResume() {
super.onResume();
// If running on Android 6 (Marshmallow) and later, check to see if the necessary permissions // have been grantedif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mPermissionsGranted = hasPermissions(this, mRequiredPermissions);
if (!mPermissionsGranted)
ActivityCompat.requestPermissions(this, mRequiredPermissions, PERMISSIONS_REQUEST_CODE);
} elsemPermissionsGranted = true;
// Start the camera preview displayif (mPermissionsGranted && goCoderCameraView != null) {
if (goCoderCameraView.isPreviewPaused())
goCoderCameraView.onResume();
elsegoCoderCameraView.startPreview();
}
}
@Overridepublic void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
mPermissionsGranted = true;
switch (requestCode) {
case PERMISSIONS_REQUEST_CODE: {
// Check the result of each permission grantedfor (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
mPermissionsGranted = false;
}
}
}
}
}
//// Utility method to check the status of a permissions request for an array of permission identifiers//private static boolean hasPermissions(Context context, String[] permissions) {
for (String permission : permissions)
if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED)
return false;
return true;
}
@Overridepublic void onWZStatus(final WOWZStatus goCoderStatus) {
// A successful status transition has been reported by the GoCoder SDKfinal StringBuffer statusMessage = new StringBuffer("Broadcast status: ");
switch (goCoderStatus.getState()) {
case WOWZState.STARTING:
statusMessage.append("Broadcast initialization");
break;
case WOWZState.READY:
statusMessage.append("Ready to begin streaming");
break;
case WOWZState.RUNNING:
statusMessage.append("Streaming is active");
break;
case WOWZState.STOPPING:
statusMessage.append("Broadcast shutting down");
break;
case WOWZState.IDLE:
statusMessage.append("The broadcast is stopped");
break;
default:
return;
}
}
@Overridepublic void onWZError ( final WOWZStatus goCoderStatus){
// If an error is reported by the GoCoder SDK, display a message // containing the error details using the U/I threadnew Handler(Looper.getMainLooper()).post(new Runnable() {
@Overridepublic void run() {
Toast.makeText(MainActivity.this,
"Streaming error: " + goCoderStatus.getLastError().getErrorDescription(),
Toast.LENGTH_LONG).show();
}
});
}
@Overridepublic void onClick(View v) {
// return if the user hasn't granted the app the necessary permissionsif (!mPermissionsGranted) return;
// Ensure the minimum set of configuration settings have been specified necessary to // initiate a broadcast streaming sessionWOWZStreamingError configValidationError = goCoderBroadcastConfig.validateForBroadcast();
if (configValidationError != null) {
Toast.makeText(this, configValidationError.getErrorDescription(), Toast.LENGTH_LONG).show();
} else if (goCoderBroadcaster.getStatus().isRunning()) {
// Stop the broadcast that is currently runninggoCoderBroadcaster.endBroadcast(this);
} else {
// Start streaminggoCoderBroadcaster.startBroadcast(goCoderBroadcastConfig, this);
}
}
}
package com.example.hu.myapplication;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.wowza.gocoder.sdk.api.WowzaGoCoder;
import com.wowza.gocoder.sdk.api.broadcast.WOWZBroadcast;
import com.wowza.gocoder.sdk.api.broadcast.WOWZBroadcastAPI;
import com.wowza.gocoder.sdk.api.broadcast.WOWZBroadcastConfig;
import com.wowza.gocoder.sdk.api.configuration.WOWZMediaConfig;
import com.wowza.gocoder.sdk.api.devices.WOWZAudioDevice;
import com.wowza.gocoder.sdk.api.devices.WOWZCamera;
import com.wowza.gocoder.sdk.api.devices.WOWZCameraView;
import com.wowza.gocoder.sdk.api.errors.WOWZError;
import com.wowza.gocoder.sdk.api.errors.WOWZStreamingError;
import com.wowza.gocoder.sdk.api.geometry.WOWZSize;
import com.wowza.gocoder.sdk.api.status.WOWZState;
import com.wowza.gocoder.sdk.api.status.WOWZStatus;
import com.wowza.gocoder.sdk.api.status.WOWZStatusCallback;
import static com.wowza.gocoder.sdk.api.WowzaGoCoder.hasPermissions;
public class MainActivity extends AppCompatActivity implements WOWZStatusCallback, View.OnClickListener {
// The top-level GoCoder API interfaceprivate WowzaGoCoder goCoder;
// The GoCoder SDK camera viewprivate WOWZCameraView goCoderCameraView;
// The GoCoder SDK audio deviceprivate WOWZAudioDevice goCoderAudioDevice;
// The GoCoder SDK broadcasterprivate WOWZBroadcast goCoderBroadcaster;
// The broadcast configuration settingsprivate WOWZBroadcastConfig goCoderBroadcastConfig;
// Properties needed for Android 6+ permissions handlingprivate static final int PERMISSIONS_REQUEST_CODE = 0x1;
private boolean mPermissionsGranted = true;
private String[] mRequiredPermissions = new String[]{
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO};
@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WowzaGoCoder goCoder = WowzaGoCoder.init(this, "EDEV4-pCZ7p-r7eB9-FTXUb-EANnZ-XxDpK-*********");
if (goCoder == null) {
// If initialization failed, retrieve the last error and display itWOWZError goCoderInitError = WowzaGoCoder.getLastError();
Toast.makeText(this,
"GoCoder SDK error: " + goCoderInitError.getErrorDescription(),
Toast.LENGTH_LONG).show();
return;
}
// Associate the WOWZCameraView defined in the U/I layout with the corresponding class membergoCoderCameraView = (WOWZCameraView) findViewById(R.id.camera_preview);
// Create an audio device instance for capturing and broadcasting audiogoCoderAudioDevice = new WOWZAudioDevice();
// Create a broadcaster instancegoCoderBroadcaster = new WOWZBroadcast();
// Create a configuration instance for the broadcastergoCoderBroadcastConfig = new WOWZBroadcastConfig(WOWZMediaConfig.FRAME_SIZE_1920x1080);
// Set the connection properties for the target Wowza Streaming Engine server or Wowza Streaming Cloud live streamgoCoderBroadcastConfig.setHostAddress("rtsp://d41a1f.entrypoint.cloud.wowza.com/app-1da1");
goCoderBroadcastConfig.setPortNumber(1935);
goCoderBroadcastConfig.setApplicationName("8e0117a7");
goCoderBroadcastConfig.setStreamName("myStream");
// Designate the camera preview as the video sourcegoCoderBroadcastConfig.setVideoBroadcaster(goCoderCameraView);
// Designate the audio device as the audio broadcastergoCoderBroadcastConfig.setAudioBroadcaster(goCoderAudioDevice);
/*WOWZBroadcastConfig wowzBroadcastConfig; //wowzBroadcastConfig.setVideoBroadcaster(WOWZBroadcastAPI.VideoBroadcaster); // Assign the camera view WOWZCameraView goCoderCameraView = (WOWZCameraView) findViewById(R.id.cameraPreview); goCoder.setCameraView(goCoderCameraView); goCoder.startCameraPreview();// Start the camera preview goCoderCameraView.startPreview(); int numCameras = WOWZCamera.getNumberOfDeviceCameras(this); // Set the active camera to the front camera if it's not active if (!goCoderCameraView.getCamera().isFront()) goCoderCameraView.switchCamera(); // Set the camera preview to 720p WOWZSize actualFrameSize = goCoderCameraView.setFrameSize(new WOWZSize(1280, 720)); // Set the cropping mode so that the full frame is displayed, potentially cropped goCoderCameraView.setScaleMode(WOWZMediaConfig.FILL_VIEW);*/Log.i("WowzaSDKVersion: ", goCoder.SDK_VERSION);
Button broadcastButton = (Button) findViewById(R.id.broadcast_button);
broadcastButton.setOnClickListener(this);
}
@Overridepublic void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
if (rootView != null)
rootView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_FULLSCREEN| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
@Overrideprotected void onResume() {
super.onResume();
// If running on Android 6 (Marshmallow) and later, check to see if the necessary permissions // have been grantedif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mPermissionsGranted = hasPermissions(this, mRequiredPermissions);
if (!mPermissionsGranted)
ActivityCompat.requestPermissions(this, mRequiredPermissions, PERMISSIONS_REQUEST_CODE);
} elsemPermissionsGranted = true;
// Start the camera preview displayif (mPermissionsGranted && goCoderCameraView != null) {
if (goCoderCameraView.isPreviewPaused())
goCoderCameraView.onResume();
elsegoCoderCameraView.startPreview();
}
}
@Overridepublic void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
mPermissionsGranted = true;
switch (requestCode) {
case PERMISSIONS_REQUEST_CODE: {
// Check the result of each permission grantedfor (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
mPermissionsGranted = false;
}
}
}
}
}
//// Utility method to check the status of a permissions request for an array of permission identifiers//private static boolean hasPermissions(Context context, String[] permissions) {
for (String permission : permissions)
if (context.checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED)
return false;
return true;
}
@Overridepublic void onWZStatus(final WOWZStatus goCoderStatus) {
// A successful status transition has been reported by the GoCoder SDKfinal StringBuffer statusMessage = new StringBuffer("Broadcast status: ");
switch (goCoderStatus.getState()) {
case WOWZState.STARTING:
statusMessage.append("Broadcast initialization");
break;
case WOWZState.READY:
statusMessage.append("Ready to begin streaming");
break;
case WOWZState.RUNNING:
statusMessage.append("Streaming is active");
break;
case WOWZState.STOPPING:
statusMessage.append("Broadcast shutting down");
break;
case WOWZState.IDLE:
statusMessage.append("The broadcast is stopped");
break;
default:
return;
}
}
@Overridepublic void onWZError ( final WOWZStatus goCoderStatus){
// If an error is reported by the GoCoder SDK, display a message // containing the error details using the U/I threadnew Handler(Looper.getMainLooper()).post(new Runnable() {
@Overridepublic void run() {
Toast.makeText(MainActivity.this,
"Streaming error: " + goCoderStatus.getLastError().getErrorDescription(),
Toast.LENGTH_LONG).show();
}
});
}
@Overridepublic void onClick(View v) {
// return if the user hasn't granted the app the necessary permissionsif (!mPermissionsGranted) return;
// Ensure the minimum set of configuration settings have been specified necessary to // initiate a broadcast streaming sessionWOWZStreamingError configValidationError = goCoderBroadcastConfig.validateForBroadcast();
if (configValidationError != null) {
Toast.makeText(this, configValidationError.getErrorDescription(), Toast.LENGTH_LONG).show();
} else if (goCoderBroadcaster.getStatus().isRunning()) {
// Stop the broadcast that is currently runninggoCoderBroadcaster.endBroadcast(this);
} else {
// Start streaminggoCoderBroadcaster.startBroadcast(goCoderBroadcastConfig, this);
}
}
}
Hi @Jesse Hu, I am having someone look at it right now for you. I’ll respond shortly. Thanks for your patience.
Are you using your engine trial license key instead of the Gocoder SDK key? The Engine Developer key usually starts with EDEV4 and that is not the one to insert there. Can you try your SDK license key?
I replaced it with the SDK license key and now it crashes.
The only thing to do at this point is open a support ticket and have us run full tests on your log files to find the issue. I’m sorry I wasn’t able to resolve it for you here in the forums. We just need to take a closer look at everything and the engineers only do that through tickets. Thanks for your communication with me.
https://www.wowza.com/support/open-ticket