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.
package com.example.hu.gather
import android.Manifest
import android.support.v7.app.AppCompatActivity
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.content.pm.PackageManager
import android.support.v4.content.PermissionChecker.checkCallingOrSelfPermission
import android.support.v4.app.ActivityCompat
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>(R.id.broadcast_button) 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(
this@MainActivity,
statusMessage,
Toast.LENGTH_LONG).show()
})
}
// // 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(
this@MainActivity,
"Streaming error: " + goCoderStatus.lastError.errorDescription,
Toast.LENGTH_LONG).show()
})
}
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?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
goCoderCameraView = findViewById<View>(R.id.camera_preview) 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>(R.id.camera_preview) 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://d41a1f.entrypoint.cloud.wowza.com/app-1da1" 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) {
super.onWindowFocusChanged(hasFocus)
val rootView = window.decorView.findViewById<View>(android.R.id.content)
if (rootView != null)
rootView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLEor View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATIONor View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREENor View.SYSTEM_UI_FLAG_HIDE_NAVIGATIONor View.SYSTEM_UI_FLAG_FULLSCREENor View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
}
// // Called when an activity is brought to the foreground //override fun onResume() {
super.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) {
PERMISSIONS_REQUEST_CODE -> {
// 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}
}
<com.wowza.gocoder.sdk.api.devices.WOWZCameraViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/camera_preview"wowza:scaleMode="fill"wowza:defaultCamera="back"wowza:frameSizePreset="frameSize1280x720"/>
<!-- 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.
HEY GUESSS WHAT? I CAN’T UPLOAD PICTURES EITHER
My broadcast button is upside down the right corner. how does that happen