Fix audio guidance issue
This commit is contained in:
parent
4411f76eb2
commit
5fd7ddf1ff
5 changed files with 47 additions and 4 deletions
|
@ -10,6 +10,7 @@ import net.osmand.GPXUtilities.GPXFile;
|
|||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.Version;
|
||||
import net.osmand.access.AccessibilityPlugin;
|
||||
import net.osmand.access.AccessibleActivity;
|
||||
import net.osmand.access.AccessibleAlertBuilder;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
|
@ -545,7 +546,8 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
|
|||
startActivity(newIntent);
|
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
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 (mapView.isZooming()) {
|
||||
changeZoom(mapView.getZoom() + 2);
|
||||
|
|
|
@ -6,8 +6,11 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.voice.CommandPlayer;
|
||||
import android.media.AudioManager;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
||||
|
@ -61,6 +64,19 @@ public class OsmandExtraSettings extends OsmandPlugin {
|
|||
app.getString(R.string.voice_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);
|
||||
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);
|
||||
|
||||
|
||||
|
|
|
@ -15,4 +15,6 @@ public interface CommandPlayer {
|
|||
public abstract void clear();
|
||||
|
||||
public abstract List<String> execute(List<Struct> listStruct);
|
||||
|
||||
public abstract void updateAudioStream(int streamType);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -30,6 +31,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
// indicates that player is ready to play first file
|
||||
private volatile boolean playNext = true;
|
||||
private List<String> filesToPlay = Collections.synchronizedList(new ArrayList<String>());
|
||||
private int streamType;
|
||||
|
||||
|
||||
public MediaCommandPlayerImpl(Context ctx, String voiceProvider)
|
||||
|
@ -37,6 +39,14 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
{
|
||||
super(ctx, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION);
|
||||
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
|
||||
|
@ -82,6 +92,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
public void onCompletion(MediaPlayer mp) {
|
||||
mp.release();
|
||||
mediaPlayer = new MediaPlayer();
|
||||
mediaPlayer.setAudioStreamType(streamType);
|
||||
int sleep = 60;
|
||||
boolean delay = true;
|
||||
while (!filesToPlay.isEmpty() && delay) {
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package net.osmand.plus.voice;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import alice.tuprolog.Struct;
|
||||
|
@ -53,6 +55,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
private TextToSpeech mTts;
|
||||
private Context mTtsContext;
|
||||
private String language;
|
||||
private HashMap<String, String> params = new HashMap<String, String>();
|
||||
|
||||
protected TTSCommandPlayerImpl(Activity ctx, String voiceProvider)
|
||||
throws CommandPlayerException {
|
||||
|
@ -65,8 +68,12 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
throw new CommandPlayerException(
|
||||
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
|
||||
public void playCommands(CommandBuilder builder) {
|
||||
|
@ -76,11 +83,11 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
for (String s : execute) {
|
||||
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) {
|
||||
internalClear();
|
||||
|
@ -165,4 +172,9 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
|||
return new File(voiceDir, CONFIG_FILE).exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAudioStream(int streamType) {
|
||||
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, streamType+"");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue