diff options
| author | 2011-07-06 02:01:48 -0700 | |
|---|---|---|
| committer | 2011-07-06 02:01:48 -0700 | |
| commit | e074e221a8d80b79ec2e8eca0dc026bfcce87cd2 (patch) | |
| tree | fcea9a30618767d68b1e8412e3a73bff91ae904a | |
| parent | 4431c05f136bc1073b368221e3515aaf7fe8424e (diff) | |
| parent | 963719869967cc257e666809aeb9bff3f25117ed (diff) | |
Merge "Minor changes to AudioTrack handling"
| -rw-r--r-- | core/java/android/speech/tts/AudioPlaybackHandler.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/core/java/android/speech/tts/AudioPlaybackHandler.java b/core/java/android/speech/tts/AudioPlaybackHandler.java index a3686b77d1b7..c7603ee2b5f5 100644 --- a/core/java/android/speech/tts/AudioPlaybackHandler.java +++ b/core/java/android/speech/tts/AudioPlaybackHandler.java @@ -74,6 +74,12 @@ class AudioPlaybackHandler { removeMessages(token); if (token.getType() == MessageParams.TYPE_SYNTHESIS) { + AudioTrack current = ((SynthesisMessageParams) token).getAudioTrack(); + if (current != null) { + // Stop the current audio track if it's still playing. + // The audio track is thread safe in this regard. + current.stop(); + } mQueue.add(new ListEntry(SYNTHESIS_DONE, token, HIGH_PRIORITY)); } else { final MessageParams current = getCurrentParams(); @@ -393,9 +399,10 @@ class AudioPlaybackHandler { try { if (audioTrack != null) { - audioTrack.flush(); - audioTrack.stop(); if (DBG) Log.d(TAG, "Releasing audio track [" + audioTrack.hashCode() + "]"); + // The last call to AudioTrack.write( ) will return only after + // all data from the audioTrack has been sent to the mixer, so + // it's safe to release at this point. audioTrack.release(); } } finally { |