Skip to content

Commit

Permalink
Fix crash when stopping player.
Browse files Browse the repository at this point in the history
  • Loading branch information
thetwom committed Aug 11, 2020
1 parent 4c93c7f commit 2ed57b3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "de.moekadu.metronome"
minSdkVersion 23
targetSdkVersion 29
versionCode 22
versionName "1.6.7"
versionCode 23
versionName "1.6.8"
resValue "string", "version", "${versionName}"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/de/moekadu/metronome/AudioMixer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ class AudioMixer (val context: Context) {

/// Stop playing
fun stop() {
if(player != null) {
player?.pause()
player?.flush()
player?.release()
player?.let {audioTrack ->
player = null
audioTrack.pause()
audioTrack.flush()
audioTrack.release()
}
isPlaying = false
}
Expand Down Expand Up @@ -353,7 +353,7 @@ class AudioMixer (val context: Context) {
}
val numWrite = player?.write(mixingBuffer, 0, mixingBuffer.size, AudioTrack.WRITE_NON_BLOCKING)
// Log.v("AudioMixer", "AudioMixer:mixAndQueueTracks : wrote $numWrite to audioTrack")
if(numWrite != mixingBuffer.size)
if(numWrite != mixingBuffer.size && numWrite != null)
throw RuntimeException("Nonblocking write of ${mixingBuffer.size} samples to AudioTrack not possible")
}
}
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/23.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash when stopping the player

0 comments on commit 2ed57b3

Please sign in to comment.