mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-06-05 21:59:31 +02:00
properly handle multiple recordings in a row
This commit is contained in:
@ -29,7 +29,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
private var recorder: MediaRecorder? = null
|
private var recorder: MediaRecorder? = null
|
||||||
private var currFilePath = ""
|
private var currFilePath = ""
|
||||||
private var duration = 0
|
private var duration = 0
|
||||||
private val timer = Timer()
|
private var timer = Timer()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -136,7 +136,9 @@ class MainActivity : SimpleActivity() {
|
|||||||
try {
|
try {
|
||||||
prepare()
|
prepare()
|
||||||
start()
|
start()
|
||||||
timer.scheduleAtFixedRate(timerTask, 1000, 1000)
|
duration = 0
|
||||||
|
timer = Timer()
|
||||||
|
timer.scheduleAtFixedRate(getTimerTask(), 1000, 1000)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
}
|
}
|
||||||
@ -145,6 +147,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun stopRecording() {
|
private fun stopRecording() {
|
||||||
timer.cancel()
|
timer.cancel()
|
||||||
|
|
||||||
recorder?.apply {
|
recorder?.apply {
|
||||||
stop()
|
stop()
|
||||||
release()
|
release()
|
||||||
@ -197,7 +200,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
toast(msg, Toast.LENGTH_LONG)
|
toast(msg, Toast.LENGTH_LONG)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val timerTask = object : TimerTask() {
|
private fun getTimerTask() = object : TimerTask() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
duration++
|
duration++
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
Reference in New Issue
Block a user