- Fix crash when user click on button when no permission were given

- Fix live abort when user goto settings to enable permissions
This commit is contained in:
Schoumi 2021-10-18 18:11:54 +02:00
parent 097d8f73c2
commit f13a8236c7

View File

@ -119,6 +119,7 @@ class StreamActivity : AppCompatActivity() {
askStopLive(STOP) askStopLive(STOP)
} }
binding.switchCamera.setOnClickListener { rtmpCamera2.switchCamera() } binding.switchCamera.setOnClickListener { rtmpCamera2.switchCamera() }
binding.switchCamera.visibility = View.GONE
binding.muteMicro.setOnClickListener { binding.muteMicro.setOnClickListener {
if (rtmpCamera2.isAudioMuted) { if (rtmpCamera2.isAudioMuted) {
rtmpCamera2.enableAudio() rtmpCamera2.enableAudio()
@ -129,6 +130,7 @@ class StreamActivity : AppCompatActivity() {
binding.muteMicro.setImageResource(R.drawable.baseline_volume_off_24) binding.muteMicro.setImageResource(R.drawable.baseline_volume_off_24)
} }
} }
binding.muteMicro.visibility = View.GONE
binding.flash.setOnClickListener { binding.flash.setOnClickListener {
if (rtmpCamera2.isLanternEnabled) { if (rtmpCamera2.isLanternEnabled) {
rtmpCamera2.disableLantern() rtmpCamera2.disableLantern()
@ -139,6 +141,7 @@ class StreamActivity : AppCompatActivity() {
binding.flash.setImageResource(R.drawable.baseline_flash_on_24) binding.flash.setImageResource(R.drawable.baseline_flash_on_24)
} }
} }
binding.flash.visibility = View.GONE
binding.rotation.setOnClickListener { binding.rotation.setOnClickListener {
if (rotationIsLanternEnabled) { if (rotationIsLanternEnabled) {
@ -150,6 +153,7 @@ class StreamActivity : AppCompatActivity() {
binding.rotation.setImageResource(R.drawable.baseline_screen_rotation_24) binding.rotation.setImageResource(R.drawable.baseline_screen_rotation_24)
} }
} }
binding.rotation.visibility = View.GONE
binding.surfaceView.holder.addCallback(object: SurfaceHolder.Callback { binding.surfaceView.holder.addCallback(object: SurfaceHolder.Callback {
override fun surfaceCreated(p0: SurfaceHolder) { override fun surfaceCreated(p0: SurfaceHolder) {
surfaceInit = true surfaceInit = true
@ -208,6 +212,7 @@ class StreamActivity : AppCompatActivity() {
binding.permissionInfo.visibility = View.VISIBLE binding.permissionInfo.visibility = View.VISIBLE
binding.gotoPermission.visibility = View.VISIBLE binding.gotoPermission.visibility = View.VISIBLE
binding.surfaceView.visibility = View.GONE binding.surfaceView.visibility = View.GONE
binding.gotoPermission.setOnClickListener { binding.gotoPermission.setOnClickListener {
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.fromParts("package", packageName, null) intent.data = Uri.fromParts("package", packageName, null)
@ -217,6 +222,7 @@ class StreamActivity : AppCompatActivity() {
ActivityCompat.requestPermissions(this, permissions.toTypedArray(), 1) ActivityCompat.requestPermissions(this, permissions.toTypedArray(), 1)
} }
} else { } else {
binding.surfaceView.visibility = View.VISIBLE
permissionGiven = true permissionGiven = true
if(surfaceInit && !streamIsActive) if(surfaceInit && !streamIsActive)
startStream() startStream()
@ -225,7 +231,7 @@ class StreamActivity : AppCompatActivity() {
override fun onStop() { override fun onStop() {
super.onStop() super.onStop()
if (!hasWindowFocus()) { if (this@StreamActivity::rtmpCamera2.isInitialized && !hasWindowFocus()) {
unregisterReceiver(lockReceiver) unregisterReceiver(lockReceiver)
setResult(BACKGROUND) setResult(BACKGROUND)
finish() finish()
@ -259,6 +265,10 @@ class StreamActivity : AppCompatActivity() {
binding.permissionInfo.visibility = View.GONE binding.permissionInfo.visibility = View.GONE
binding.gotoPermission.visibility = View.GONE binding.gotoPermission.visibility = View.GONE
binding.surfaceView.visibility = View.VISIBLE binding.surfaceView.visibility = View.VISIBLE
binding.muteMicro.visibility = View.VISIBLE
binding.rotation.visibility = View.VISIBLE
binding.switchCamera.visibility = View.VISIBLE
binding.flash.visibility = View.VISIBLE
val connectChecker : ConnectCheckerRtmp = object : ConnectCheckerRtmp { val connectChecker : ConnectCheckerRtmp = object : ConnectCheckerRtmp {
override fun onConnectionSuccessRtmp() { override fun onConnectionSuccessRtmp() {
@ -333,9 +343,6 @@ class StreamActivity : AppCompatActivity() {
} }
} }
rtmpCamera2.startPreview(CameraHelper.Facing.BACK, width,height) rtmpCamera2.startPreview(CameraHelper.Facing.BACK, width,height)
//start stream //start stream