@ -185,6 +185,7 @@ class AudioRecorderManager {
@Volatile var elapsedMs : Int = 0 ; private set
@Volatile var elapsedMs : Int = 0 ; private set
var pausedElapsedMs : Int = 0 ; private set
var pausedElapsedMs : Int = 0 ; private set
private var playThread : Thread ? = null
private var playThread : Thread ? = null
@Volatile private var stopped = false
fun playVoiceFile ( filePath : String , onProgress : ( ( Float ) -> Unit ) ? = null , onComplete : ( ) -> Unit = { } ) {
fun playVoiceFile ( filePath : String , onProgress : ( ( Float ) -> Unit ) ? = null , onComplete : ( ) -> Unit = { } ) {
playFromPosition ( filePath , 0 , onProgress , onComplete )
playFromPosition ( filePath , 0 , onProgress , onComplete )
@ -245,19 +246,22 @@ class AudioRecorderManager {
} catch ( e : Exception ) {
} catch ( e : Exception ) {
LogManager . addLog ( " ERROR " , " AudioPlayer " , " play error: ${e.message} " )
LogManager . addLog ( " ERROR " , " AudioPlayer " , " play error: ${e.message} " )
}
}
playing = false ; isPaused = false
if ( ! stopped ) {
onComplete ( )
playing = false ; isPaused = false ; onComplete ( )
}
} . apply { start ( ) }
} . apply { start ( ) }
}
}
fun pausePlayback ( ) {
fun pausePlayback ( ) {
pausedElapsedMs = elapsedMs
pausedElapsedMs = elapsedMs
isPaused = true ; playing = false
stopped = true ; isPaused = true ; playing = false
playThread ?. join ( 500 ) ; playThread = null
playThread ?. join ( 500 ) ; playThread = null
stopped = false
}
}
fun stopPlayback ( ) {
fun stopPlayback ( ) {
playing = false ; isPaused = false ; pausedElapsedMs = 0
stopped = true ; playing = false ; isPaused = false ; pausedElapsedMs = 0
playThread ?. join ( 500 ) ; playThread = null
playThread ?. join ( 500 ) ; playThread = null
stopped = false
}
}
}
}