Fix audio guidance issue

This commit is contained in:
Victor Shcherb 2012-05-28 01:47:02 +02:00
parent 4411f76eb2
commit 5fd7ddf1ff
5 changed files with 47 additions and 4 deletions

View file

@ -10,6 +10,7 @@ import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.LogUtil; import net.osmand.LogUtil;
import net.osmand.Version; import net.osmand.Version;
import net.osmand.access.AccessibilityPlugin;
import net.osmand.access.AccessibleActivity; import net.osmand.access.AccessibleActivity;
import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
@ -545,7 +546,8 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
startActivity(newIntent); startActivity(newIntent);
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return true; return true;
} else if (!routingHelper.isFollowingMode()) { } else if (!routingHelper.isFollowingMode() && OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) != null) {
// Find more appropriate plugin for it?
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) {
if (mapView.isZooming()) { if (mapView.isZooming()) {
changeZoom(mapView.getZoom() + 2); changeZoom(mapView.getZoom() + 2);

View file

@ -6,8 +6,11 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.voice.CommandPlayer;
import android.media.AudioManager; import android.media.AudioManager;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
@ -61,6 +64,19 @@ public class OsmandExtraSettings extends OsmandPlugin {
app.getString(R.string.voice_stream_voice_call)}, app.getString(R.string.voice_stream_voice_call)},
new Integer[] {AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION, AudioManager.STREAM_VOICE_CALL}, new Integer[] {AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION, AudioManager.STREAM_VOICE_CALL},
R.string.choose_audio_stream, R.string.choose_audio_stream_descr); R.string.choose_audio_stream, R.string.choose_audio_stream_descr);
final OnPreferenceChangeListener prev = lp.getOnPreferenceChangeListener();
lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
prev.onPreferenceChange(preference, newValue);
CommandPlayer player = app.getPlayer();
if(player != null) {
player.updateAudioStream(settings.AUDIO_STREAM_GUIDANCE.get());
}
return true;
}
});
cat.addPreference(lp); cat.addPreference(lp);

View file

@ -15,4 +15,6 @@ public interface CommandPlayer {
public abstract void clear(); public abstract void clear();
public abstract List<String> execute(List<Struct> listStruct); public abstract List<String> execute(List<Struct> listStruct);
public abstract void updateAudioStream(int streamType);
} }

View file

@ -7,6 +7,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import net.osmand.LogUtil; import net.osmand.LogUtil;
import net.osmand.plus.OsmandApplication;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -30,6 +31,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer {
// indicates that player is ready to play first file // indicates that player is ready to play first file
private volatile boolean playNext = true; private volatile boolean playNext = true;
private List<String> filesToPlay = Collections.synchronizedList(new ArrayList<String>()); private List<String> filesToPlay = Collections.synchronizedList(new ArrayList<String>());
private int streamType;
public MediaCommandPlayerImpl(Context ctx, String voiceProvider) public MediaCommandPlayerImpl(Context ctx, String voiceProvider)
@ -37,6 +39,14 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer {
{ {
super(ctx, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION); super(ctx, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION);
mediaPlayer = new MediaPlayer(); mediaPlayer = new MediaPlayer();
OsmandApplication osmApp = (OsmandApplication) ctx.getApplicationContext();
this.streamType = osmApp.getSettings().AUDIO_STREAM_GUIDANCE.get();
mediaPlayer.setAudioStreamType(streamType);
}
@Override
public void updateAudioStream(int streamType) {
this.streamType = streamType;
} }
@Override @Override
@ -82,6 +92,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer {
public void onCompletion(MediaPlayer mp) { public void onCompletion(MediaPlayer mp) {
mp.release(); mp.release();
mediaPlayer = new MediaPlayer(); mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(streamType);
int sleep = 60; int sleep = 60;
boolean delay = true; boolean delay = true;
while (!filesToPlay.isEmpty() && delay) { while (!filesToPlay.isEmpty() && delay) {

View file

@ -1,10 +1,12 @@
package net.osmand.plus.voice; package net.osmand.plus.voice;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import net.osmand.Algoritms; import net.osmand.Algoritms;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
import alice.tuprolog.Struct; import alice.tuprolog.Struct;
@ -53,6 +55,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
private TextToSpeech mTts; private TextToSpeech mTts;
private Context mTtsContext; private Context mTtsContext;
private String language; private String language;
private HashMap<String, String> params = new HashMap<String, String>();
protected TTSCommandPlayerImpl(Activity ctx, String voiceProvider) protected TTSCommandPlayerImpl(Activity ctx, String voiceProvider)
throws CommandPlayerException { throws CommandPlayerException {
@ -65,9 +68,13 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
throw new CommandPlayerException( throw new CommandPlayerException(
ctx.getString(R.string.voice_data_corrupted)); ctx.getString(R.string.voice_data_corrupted));
} }
initializeEngine(ctx.getApplicationContext(), ctx); OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
initializeEngine(app, ctx);
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, app.getSettings().AUDIO_STREAM_GUIDANCE.get().toString());
} }
@Override @Override
public void playCommands(CommandBuilder builder) { public void playCommands(CommandBuilder builder) {
if (mTts != null) { if (mTts != null) {
@ -76,11 +83,11 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
for (String s : execute) { for (String s : execute) {
bld.append(s).append(' '); bld.append(s).append(' ');
} }
mTts.speak(bld.toString(), TextToSpeech.QUEUE_ADD, null); mTts.speak(bld.toString(), TextToSpeech.QUEUE_ADD, params);
} }
} }
private void initializeEngine(final Context ctx, final Activity act) private void initializeEngine(final OsmandApplication ctx, final Activity act)
{ {
if (mTts != null && mTtsContext != ctx) { if (mTts != null && mTtsContext != ctx) {
internalClear(); internalClear();
@ -165,4 +172,9 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
return new File(voiceDir, CONFIG_FILE).exists(); return new File(voiceDir, CONFIG_FILE).exists();
} }
@Override
public void updateAudioStream(int streamType) {
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, streamType+"");
}
} }