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

Loading…
Cancel
Save