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