Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added onOffRoute call and removed queue from NavigationInstructionPlayer #986

Merged
merged 1 commit into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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