1
0
Fork 0

Fix bug where "end of stream" event was being triggered too early

This commit is contained in:
Eoin Mcloughlin 2020-05-16 18:26:37 +01:00
parent f822ed8474
commit 65a3a97caf
3 changed files with 29 additions and 3 deletions

View file

@ -418,17 +418,21 @@ class DitDahSoundStream : AudioTrack.OnPlaybackPositionUpdateListener {
SoundTypes.WORD_SPACE -> mWordSpacingSound
}
mSoundPlayer.write(soundToWrite, 0, soundToWrite.size)
// Keep track of the number of samples we wrote to fire our "finished" listener
// This is done before the write(), since a blocking call might erroneously cause
// us to detect the end of the lesson to early.
// (Seems "frames" and "samples" are interchangeable in the API?)
mNumberFramesWritten += soundToWrite.size
mSoundPlayer.setNotificationMarkerPosition(mNumberFramesWritten)
mSoundPlayer.write(soundToWrite, 0, soundToWrite.size)
// If this is the first symbol, we'll need to start playing.
if (mSoundPlayer.playState != AudioTrack.PLAYSTATE_PLAYING)
mSoundPlayer.play()
}
}
// Optional listener for stream finished event
@ -470,7 +474,8 @@ class DitDahSoundStream : AudioTrack.OnPlaybackPositionUpdateListener {
.build();
override fun onMarkerReached(track: AudioTrack?) {
streamNotificationListener?.streamFinished(this)
if(track!!.notificationMarkerPosition >= mNumberFramesWritten)
streamNotificationListener?.streamFinished(this)
}
override fun onPeriodicNotification(track: AudioTrack?) {

View file

@ -0,0 +1,12 @@
package es.eoinrul.ecwt
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class TrainingResultsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_training_results)
}
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TrainingResultsActivity">
</androidx.constraintlayout.widget.ConstraintLayout>