diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewModel.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewModel.java index 9c07994887f..3e5c25e637e 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewModel.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewModel.java @@ -256,6 +256,7 @@ public void onProgressChange(Location location, RouteProgress routeProgress) { @Override public void userOffRoute(Location location) { if (hasNetworkConnection()) { + instructionPlayer.onOffRoute(); Point newOrigin = Point.fromLngLat(location.getLongitude(), location.getLatitude()); sendEventOffRoute(newOrigin); } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/voice/NavigationInstructionPlayer.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/voice/NavigationInstructionPlayer.java index bfaf2bf356c..81491407ab3 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/voice/NavigationInstructionPlayer.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/voice/NavigationInstructionPlayer.java @@ -8,27 +8,23 @@ import com.mapbox.services.android.navigation.v5.milestone.VoiceInstructionMilestone; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; - public class NavigationInstructionPlayer implements InstructionListener { private AudioManager instructionAudioManager; private AudioFocusRequest instructionFocusRequest; private MapboxSpeechPlayer mapboxSpeechPlayer; private AndroidSpeechPlayer androidSpeechPlayer; - private Queue instructionQueue; + private VoiceInstructionMilestone voiceInstructionMilestone; private boolean isMuted; public NavigationInstructionPlayer(@NonNull Context context, String language, String accessToken) { initAudioManager(context); initAudioFocusRequest(); initInstructionPlayers(context, language, accessToken); - instructionQueue = new ConcurrentLinkedQueue<>(); } public void play(VoiceInstructionMilestone voiceInstructionMilestone) { - instructionQueue.add(voiceInstructionMilestone); + this.voiceInstructionMilestone = voiceInstructionMilestone; mapboxSpeechPlayer.play(voiceInstructionMilestone.getSsmlAnnouncement()); } @@ -43,7 +39,6 @@ public void setMuted(boolean isMuted) { } public void onOffRoute() { - instructionQueue.clear(); mapboxSpeechPlayer.onOffRoute(); androidSpeechPlayer.onOffRoute(); } @@ -56,7 +51,6 @@ public void onDestroy() { @Override public void onStart() { requestAudioFocus(); - instructionQueue.poll(); } @Override @@ -67,9 +61,7 @@ public void onDone() { @Override public void onError(boolean isMapboxPlayer) { if (isMapboxPlayer) { - androidSpeechPlayer.play(instructionQueue.peek().getAnnouncement()); - } else { - instructionQueue.poll(); + androidSpeechPlayer.play(voiceInstructionMilestone.getAnnouncement()); } }