handle picture taking on a background thread

This commit is contained in:
tibbi 2018-01-12 23:47:50 +01:00
parent 103fc0cbb1
commit 2023cdca50
1 changed files with 10 additions and 8 deletions

View File

@ -296,16 +296,18 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
isWaitingForTakePictureCallback = true isWaitingForTakePictureCallback = true
mIsPreviewShown = true mIsPreviewShown = true
try { try {
mCamera!!.takePicture(null, null, takePictureCallback) Thread {
mCamera!!.takePicture(null, null, takePictureCallback)
if (config.isSoundEnabled) { if (config.isSoundEnabled) {
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
val volume = audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM) val volume = audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM)
if (volume != 0) { if (volume != 0) {
val mp = MediaPlayer.create(context, Uri.parse("file:///system/media/audio/ui/camera_click.ogg")) val mp = MediaPlayer.create(context, Uri.parse("file:///system/media/audio/ui/camera_click.ogg"))
mp?.start() mp?.start()
}
} }
} }.start()
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
} }