Fixed problem with handling delay caused by getNextTilfeToPlay()
Fixed problem where tts onUtteranceCompleted() was not called because utterance id was not set. Fixed synchronization problems.
This commit is contained in:
parent
59bea7f741
commit
d23e7c18fc
2 changed files with 17 additions and 10 deletions
|
@ -46,6 +46,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
|||
mediaPlayer = null;
|
||||
}
|
||||
|
||||
// Called from the calculating route thread.
|
||||
@Override
|
||||
public synchronized void playCommands(CommandBuilder builder) {
|
||||
filesToPlay.addAll(builder.execute());
|
||||
|
@ -79,7 +80,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
|||
}
|
||||
|
||||
/**
|
||||
* Called when the MediaPlayer is done.
|
||||
* Called when the MediaPlayer is done. The call back is on the main thread.
|
||||
*/
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
|
@ -87,7 +88,6 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
|||
playQueue();
|
||||
}
|
||||
|
||||
|
||||
private void performDelays() {
|
||||
int sleep = 0;
|
||||
while (!filesToPlay.isEmpty() && filesToPlay.get(0).startsWith(DELAY_CONST)) {
|
||||
|
@ -98,8 +98,10 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
|||
}
|
||||
}
|
||||
try {
|
||||
if (sleep != 0)
|
||||
if (sleep != 0) {
|
||||
log.debug("Delaying "+sleep);
|
||||
Thread.sleep(sleep);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
@ -109,10 +111,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
|||
String f = filesToPlay.remove(0);
|
||||
if (f != null && voiceDir != null) {
|
||||
File file = new File(voiceDir, f);
|
||||
if (file.exists())
|
||||
return file;
|
||||
else
|
||||
log.error("Unable to play, does not exist: "+file);
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -124,8 +123,13 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
|||
* @param file
|
||||
*/
|
||||
private void playFile(File file) {
|
||||
log.debug("Playing file : " + file); //$NON-NLS-1$
|
||||
if (!file.exists()) {
|
||||
log.error("Unable to play, does not exist: "+file);
|
||||
playQueue();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
log.debug("Playing file : " + file); //$NON-NLS-1$
|
||||
mediaPlayer.reset();
|
||||
mediaPlayer.setAudioStreamType(streamType);
|
||||
mediaPlayer.setDataSource(file.getAbsolutePath());
|
||||
|
|
|
@ -90,8 +90,9 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
*/
|
||||
private int ttsRequests;
|
||||
|
||||
// Called from the calculating route thread.
|
||||
@Override
|
||||
public void playCommands(CommandBuilder builder) {
|
||||
public synchronized void playCommands(CommandBuilder builder) {
|
||||
if (mTts != null) {
|
||||
final List<String> execute = builder.execute(); //list of strings, the speech text, play it
|
||||
StringBuilder bld = new StringBuilder();
|
||||
|
@ -101,6 +102,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
if (ttsRequests++ == 0)
|
||||
requestAudioFocus();
|
||||
log.debug("ttsRequests="+ttsRequests);
|
||||
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis());
|
||||
mTts.speak(bld.toString(), TextToSpeech.QUEUE_ADD, params);
|
||||
// Audio focus will be released when onUtteranceCompleted() completed is called by the TTS engine.
|
||||
}
|
||||
|
@ -160,8 +162,9 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
}
|
||||
});
|
||||
mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
|
||||
// The call back is on a binder thread.
|
||||
@Override
|
||||
public void onUtteranceCompleted(String utteranceId) {
|
||||
public synchronized void onUtteranceCompleted(String utteranceId) {
|
||||
if (--ttsRequests == 0)
|
||||
abandonAudioFocus();
|
||||
log.debug("ttsRequests="+ttsRequests);
|
||||
|
|
Loading…
Reference in a new issue