-
-
Save vincenthofmeister/96260a61d869842d5b538fc428fefe01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.cordova.*; | |
import org.json.JSONArray; | |
import org.json.JSONException; | |
import android.os.Handler; | |
import android.os.Looper; | |
import android.util.Log; | |
import android.widget.FrameLayout; | |
import com.meddlyorg.meddlyapp.R; | |
import com.wowza.gocoder.sdk.api.*; | |
import com.wowza.gocoder.sdk.api.errors.*; | |
import com.wowza.gocoder.sdk.api.WZPlatformInfo; | |
import com.wowza.gocoder.sdk.api.WowzaGoCoder; | |
import com.wowza.gocoder.sdk.api.devices.WZCameraView; | |
import com.wowza.gocoder.sdk.api.devices.WZCamera; | |
import com.wowza.gocoder.sdk.api.encoder.WZEncoderAPI; | |
import com.wowza.gocoder.sdk.api.h264.WZProfileLevel; | |
import com.wowza.gocoder.sdk.api.broadcast.WZBroadcast; | |
import com.wowza.gocoder.sdk.api.broadcast.WZBroadcastConfig; | |
import com.wowza.gocoder.sdk.api.configuration.WZMediaConfig; | |
import com.wowza.gocoder.sdk.api.configuration.WowzaConfig; | |
import com.wowza.gocoder.sdk.api.errors.WZStreamingError; | |
import com.wowza.gocoder.sdk.api.logging.WZLog; | |
import com.wowza.gocoder.sdk.api.status.WZStatus; | |
import com.wowza.gocoder.sdk.api.status.WZStatusCallback; | |
import com.wowza.gocoder.sdk.api.status.WZState; | |
import com.meddlyorg.meddlyapp.MainActivity; | |
public class Wowza extends CordovaPlugin implements WZStatusCallback { | |
// The top level GoCoder API interface | |
private WowzaGoCoder goCoder; | |
// The GoCoder SDK camera view | |
private WZCameraView goCoderCameraView; | |
//all camera holder | |
private WZCamera[] allCameras; | |
//framesize used | |
private WZMediaConfig frameSize; | |
@Override | |
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { | |
if(action.equals("startStreaming")) { | |
//Initialize the GoCoder SDK | |
this.goCoder = WowzaGoCoder.init(this.cordova.getActivity().getApplicationContext(), "GSDK-5D42-0000-0332-190D-E0DA"); | |
String frame_size = data.getString(0); | |
String host_address = data.getString(1); | |
String application_name = data.getString(2); | |
String stream_name = data.getString(3); | |
String stream_username = data.getString(4); | |
String stream_password = data.getString(5); | |
Integer stream_port = Integer.parseInt(data.getString(6)); | |
if (this.goCoder != null) | |
{ | |
// 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_1280x720); | |
// Set the address for the Wowza Streaming Engine server or Wowza Cloud | |
broadcastConfig.setHostAddress(host_address); | |
//set application name | |
broadcastConfig.setApplicationName(application_name); | |
// Set the name of the stream | |
broadcastConfig.setStreamName(stream_name); | |
// Set the password | |
broadcastConfig.setPassword(stream_password); | |
// Set the username | |
broadcastConfig.setUsername(stream_username); | |
// Set the port number | |
broadcastConfig.setPortNumber(stream_port); | |
// Update the active config | |
this.goCoder.setConfig(broadcastConfig); | |
} | |
//start the stream | |
if (this.goCoder != null) | |
{ | |
WZStreamingError configValidationError = this.goCoder.getConfig().validateForBroadcast(); | |
if (configValidationError != null) { | |
//not ready for streaming, log error | |
Log.d("VinceLog", configValidationError.getErrorDescription()); | |
} | |
else | |
{ | |
WZCamera[] allCameras = WZCamera.getAvailableDeviceCameras(); | |
this.goCoderCameraView = new WZCameraView(this.cordova.getActivity().getApplicationContext()); | |
this.goCoderCameraView.setCamera(allCameras[0]); | |
this.goCoder.startCameraPreview(); | |
WZCamera activeCamera = this.goCoderCameraView.getCamera(); | |
if (activeCamera != null && activeCamera.hasCapability(WZCamera.FOCUS_MODE_CONTINUOUS)) { | |
activeCamera.setFocusMode(WZCamera.FOCUS_MODE_CONTINUOUS); | |
this.goCoder.startStreaming(this); | |
String name = data.getString(0); | |
callbackContext.success(name); | |
return true; | |
} | |
} | |
} | |
} | |
else if (action.equals("endStreaming")){ | |
//stop the stream | |
this.goCoder.endStreaming(); | |
String name = data.getString(0); | |
callbackContext.success(name); | |
return true; | |
} | |
String name = data.getString(0); | |
callbackContext.success(name); | |
return true; | |
} | |
@Override | |
public void onWZStatus(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; | |
} | |
} //end public void onWZStatus | |
@Override | |
public void onWZError(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() { | |
Log.d("VinceLog", goCoderStatus.getLastError().getErrorDescription()); | |
} | |
}); | |
} //end public void onWZError | |
} //end public class Wowza |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment