From 8a532752eb158da5f9cb2f27058b79b1ab9996cb Mon Sep 17 00:00:00 2001 From: chgenly Date: Sat, 8 Sep 2012 22:28:39 -0700 Subject: [PATCH] Release media player when all audio files are played, rather than after each audio file is done. This prevents podcasts or music from interrupting speech. --- OsmAnd/assets/bundled_assets.xml | 0 OsmAnd/jni/Android.mk | 0 OsmAnd/jni/Application.mk | 0 OsmAnd/scripts/generate.sh | 0 .../plus/voice/MediaCommandPlayerImpl.java | 31 ++++++++++++------- 5 files changed, 19 insertions(+), 12 deletions(-) mode change 100755 => 100644 OsmAnd/assets/bundled_assets.xml mode change 100755 => 100644 OsmAnd/jni/Android.mk mode change 100755 => 100644 OsmAnd/jni/Application.mk mode change 100755 => 100644 OsmAnd/scripts/generate.sh diff --git a/OsmAnd/assets/bundled_assets.xml b/OsmAnd/assets/bundled_assets.xml old mode 100755 new mode 100644 diff --git a/OsmAnd/jni/Android.mk b/OsmAnd/jni/Android.mk old mode 100755 new mode 100644 diff --git a/OsmAnd/jni/Application.mk b/OsmAnd/jni/Application.mk old mode 100755 new mode 100644 diff --git a/OsmAnd/scripts/generate.sh b/OsmAnd/scripts/generate.sh old mode 100755 new mode 100644 diff --git a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java index 654a006911..a46bf4248d 100644 --- a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java @@ -38,9 +38,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer { throws CommandPlayerException { super(ctx, settings, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION); - mediaPlayer = new MediaPlayer(); this.streamType = settings.AUDIO_STREAM_GUIDANCE.get(); - mediaPlayer.setAudioStreamType(streamType); } @Override @@ -61,32 +59,37 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer { } private synchronized void playQueue() { - while (!filesToPlay.isEmpty() && playNext) { + if (!playNext) + return; + while (!filesToPlay.isEmpty()) { String f = filesToPlay.remove(0); if (f != null && voiceDir != null) { - boolean exists = false; // if(voiceZipFile != null){ // ZipEntry entry = voiceZipFile.getEntry(f); // exists = entry != null; // voiceZipFile.getInputStream(entry); // // } else { - File file = new File(voiceDir, f); - exists = file.exists(); -// } - if (exists) { + File file = new File(voiceDir, f); + if (file.exists()) { log.debug("Playing file : " + f); //$NON-NLS-1$ playNext = false; try { + if (mediaPlayer == null) { + mediaPlayer = new MediaPlayer(); + } + // Can't play sound file from zip it seams to be impossible only unpack and play!!! + mediaPlayer.setAudioStreamType(streamType); mediaPlayer.setDataSource(file.getAbsolutePath()); mediaPlayer.prepare(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { - mp.release(); - mediaPlayer = new MediaPlayer(); - mediaPlayer.setAudioStreamType(streamType); + // Reset prepares to speak again. Don't release because if we have more to + // say, we don't want our speech interrupted by other audio, such as music + // or a podcast. We will release when we are done speaking. + mp.reset(); int sleep = 60; boolean delay = true; while (!filesToPlay.isEmpty() && delay) { @@ -112,13 +115,17 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer { } catch (Exception e) { log.error("Error while playing voice command", e); //$NON-NLS-1$ playNext = true; - } } else { log.info("Play file not found : " + f); //$NON-NLS-1$ } } } + // Release the media player only when we are done speaking. + if (mediaPlayer != null) { + mediaPlayer.release(); + mediaPlayer = null; + } } public static boolean isMyData(File voiceDir) {