Wowza Community

Why does my app not show the CameraView?

Okay I’ve literally stripped everything down to the basics, yet now I cannot see my camera view with the broadcast button when I run it on an emulator.


import android.Manifest
import android.os.Bundle
import android.view.View
import android.Manifest.permission
import android.Manifest.permission.RECORD_AUDIOimport android.content.Context
import com.wowza.gocoder.sdk.api.broadcast.WOWZBroadcastConfig
import com.wowza.gocoder.sdk.api.broadcast.WOWZBroadcast
import com.wowza.gocoder.sdk.api.devices.WOWZAudioDevice
import com.wowza.gocoder.sdk.api.devices.WOWZCameraView
import com.wowza.gocoder.sdk.api.WowzaGoCoder
import android.widget.Toast
import com.wowza.gocoder.sdk.api.errors.WOWZError
import android.os.Build
import android.os.Handler
import com.wowza.gocoder.sdk.api.configuration.WOWZMediaConfig
import com.wowza.gocoder.sdk.api.status.WOWZStatusCallback
import com.wowza.gocoder.sdk.api.WowzaGoCoder.getLastError
import android.os.Looper
import android.widget.Button
import com.wowza.gocoder.sdk.api.errors.WOWZStreamingError
import com.wowza.gocoder.sdk.api.status.WOWZStatus
import com.wowza.gocoder.sdk.api.status.WOWZState

class MainActivity : AppCompatActivity(), WOWZStatusCallback, View.OnClickListener {

    // The top-level GoCoder API interfaceprivate var goCoder: WowzaGoCoder? = null// The GoCoder SDK camera viewprivate var goCoderCameraView: WOWZCameraView? = null// The GoCoder SDK audio deviceprivate var goCoderAudioDevice: WOWZAudioDevice? = null// The GoCoder SDK broadcasterprivate var goCoderBroadcaster: WOWZBroadcast? = null// The broadcast configuration settingsprivate var goCoderBroadcastConfig: WOWZBroadcastConfig? = null// Properties needed for Android 6+ permissions handlingprivate val PERMISSIONS_REQUEST_CODE = 0x1private var mPermissionsGranted = true    private val mRequiredPermissions = arrayOf<String>(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO)

    private val broadcastButton = findViewById<View>( as Button

    //    // The callback invoked upon changes to the state of the broadcast    //override fun onWZStatus(goCoderStatus: WOWZStatus) {
        // A successful status transition has been reported by the GoCoder SDKval statusMessage = StringBuffer("Broadcast status: ")

        when (goCoderStatus.state) {
            WOWZState.STARTING -> statusMessage.append("Broadcast initialization")

            WOWZState.READY -> statusMessage.append("Ready to begin streaming")

            WOWZState.RUNNING -> statusMessage.append("Streaming is active")

            WOWZState.STOPPING -> statusMessage.append("Broadcast shutting down")

            WOWZState.IDLE -> statusMessage.append("The broadcast is stopped")

            else -> return}

        // Display the status message using the U/I threadHandler(Looper.getMainLooper()).post(Runnable {Toast.makeText(

    //    // The callback invoked when an error occurs during a broadcast    //override fun onWZError(goCoderStatus: WOWZStatus) {
        // If an error is reported by the GoCoder SDK, display a message        // containing the error details using the U/I threadHandler(Looper.getMainLooper()).post(Runnable {Toast.makeText(
                "Streaming error: " + goCoderStatus.lastError.errorDescription,

    override fun onClick(v: View?) {
        // 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 sessionval configValidationError = goCoderBroadcastConfig?.validateForBroadcast()

        if (configValidationError != null) {
            Toast.makeText(this, configValidationError.errorDescription, Toast.LENGTH_LONG).show()
        } else if (goCoderBroadcaster?.status?.isRunning == true) {
            // Stop the broadcast that is currently runninggoCoderBroadcaster?.endBroadcast(this)
        } else {
            // Start streaminggoCoderBroadcaster?.startBroadcast(goCoderBroadcastConfig, this)

    override fun onCreate(savedInstanceState: Bundle?) {
        goCoderCameraView = findViewById<View>( as WOWZCameraView
/*        // Initialize the GoCoder SDK        goCoder = WowzaGoCoder.init(applicationContext, "GOSK-BE45-010C-83C2-991F-6551")        if (goCoder == null) {            // If initialization failed, retrieve the last error and display it            val goCoderInitError = WowzaGoCoder.getLastError()            Toast.makeText(                this,                "GoCoder SDK error: " + goCoderInitError.errorDescription,                Toast.LENGTH_LONG            ).show()            return        }        // Associate the WOWZCameraView defined in the U/I layout with the corresponding class member        goCoderCameraView = findViewById<View>( as WOWZCameraView// Create an audio device instance for capturing and broadcasting audio        goCoderAudioDevice = WOWZAudioDevice()        // Create a broadcaster instance        goCoderBroadcaster = WOWZBroadcast()// Create a configuration instance for the broadcaster        goCoderBroadcastConfig = WOWZBroadcastConfig(WOWZMediaConfig.FRAME_SIZE_1920x1080)// Set the connection properties for the target Wowza Streaming Engine server or Wowza Streaming Cloud live stream        val goCoderBConfig: WOWZBroadcastConfig? = goCoderBroadcastConfig        if (goCoderBConfig != null) {            goCoderBConfig.hostAddress = "rtsp://"            goCoderBConfig.portNumber = 1935            goCoderBConfig.applicationName = "Gather"            goCoderBConfig.streamName = "8e0117a7"// Designate the camera preview as the video source            goCoderBConfig.videoBroadcaster = goCoderCameraView// Designate the audio device as the audio broadcaster            goCoderBConfig.audioBroadcaster = goCoderAudioDevice        }        broadcastButton.setOnClickListener(this)*/}

    override fun onWindowFocusChanged(hasFocus: Boolean) {

        val rootView = window.decorView.findViewById<View>(
        if (rootView != null)

    //    // Called when an activity is brought to the foreground    //override fun onResume() {
        /*        // If running on Android 6 (Marshmallow) and later, check to see if the necessary permissions        // have been granted        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {            mPermissionsGranted = hasPermissions(this, mRequiredPermissions)            if (!mPermissionsGranted)                ActivityCompat.requestPermissions(this, mRequiredPermissions, PERMISSIONS_REQUEST_CODE)        } else            mPermissionsGranted = true        val goCoderCV = goCoderCameraView        // Start the camera preview display        if (mPermissionsGranted && goCoderCV!= null) {            if (goCoderCV.isPreviewPaused())                goCoderCV.onResume();            else                goCoderCV.startPreview();        }            */}

    //    // Callback invoked in response to a call to ActivityCompat.requestPermissions() to interpret    // the results of the permissions request    //override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
        mPermissionsGranted = true        when (requestCode) {
                // Check the result of each permission grantedfor (grantResult in 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 fun hasPermissions(context: Context, permissions: Array<String>): Boolean {
        for (permission in permissions)
            if (context.checkCallingOrSelfPermission(permission) !== PackageManager.PERMISSION_GRANTED)
                return false        return true}


<!-- The broadcast button --><Buttonandroid:id="@+id/broadcast_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:text="Broadcast"tools:layout_editor_absoluteX="140dp"tools:layout_editor_absoluteY="463dp" />

It’s all there in my xml. THIS IS SO BASIC WHY IS THIS BROKEN.


My broadcast button is upside down the right corner. how does that happen