Stop existing playback before starting new playback

pull/277/head
Kevin 3 years ago
parent db5f7b7b56
commit 8325007a5f

@ -39,7 +39,6 @@ class MainScreenViewModel(private val application: Application) : ViewModel() {
private var mediaPlayer: MediaPlayer? = null
private var recordedFile: File? = null
init {
viewModelScope.launch {
loadData()
@ -86,6 +85,8 @@ class MainScreenViewModel(private val application: Application) : ViewModel() {
}
private suspend fun readAudioSamples(file: File): FloatArray = withContext(Dispatchers.IO) {
mediaPlayer?.stop()
mediaPlayer?.release()
mediaPlayer = MediaPlayer.create(application, file.absolutePath.toUri())
mediaPlayer?.start()
return@withContext decodeWaveFile(file)

Loading…
Cancel
Save