Skip to content

Commit

Permalink
Added onOffRoute call and removed queue from NavigationInstructionPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Devota Aabel committed Jun 5, 2018
1 parent e2102d2 commit 7c2d676
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VoiceInstructionMilestone> 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());
}

Expand All @@ -43,7 +39,6 @@ public void setMuted(boolean isMuted) {
}

public void onOffRoute() {
instructionQueue.clear();
mapboxSpeechPlayer.onOffRoute();
androidSpeechPlayer.onOffRoute();
}
Expand All @@ -56,7 +51,6 @@ public void onDestroy() {
@Override
public void onStart() {
requestAudioFocus();
instructionQueue.poll();
}

@Override
Expand All @@ -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());
}
}

Expand Down

0 comments on commit 7c2d676

Please sign in to comment.