Skip to content
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
@@ -1,6 +1,7 @@
package com.mapbox.services.android.navigation.ui.v5.voice;

import android.os.AsyncTask;
import android.support.annotation.NonNull;

import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -73,11 +74,15 @@ private File saveAsFile(ResponseBody responseBody) {

@Override
protected void onPostExecute(File instructionFile) {
taskListener.onFinishedDownloading(instructionFile);
if (instructionFile == null) {
taskListener.onErrorDownloading();
} else {
taskListener.onFinishedDownloading(instructionFile);
}
}

public interface TaskListener {
void onFinishedDownloading(File file);
void onFinishedDownloading(@NonNull File file);

void onErrorDownloading();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mapbox.services.android.navigation.ui.v5.voice;

public interface InstructionListener {
interface InstructionListener {

void onStart();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private void clearInstructionUrls() {
private void executeInstructionTask(ResponseBody responseBody) {
new InstructionDownloadTask(mapboxCache.getPath(), new InstructionDownloadTask.TaskListener() {
@Override
public void onFinishedDownloading(File instructionFile) {
public void onFinishedDownloading(@NonNull File instructionFile) {
playInstructionIfUpNext(instructionFile);
instructionQueue.add(instructionFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class NavigationInstructionPlayer implements InstructionListener {
private AudioFocusRequest instructionFocusRequest;
private MapboxSpeechPlayer mapboxSpeechPlayer;
private AndroidSpeechPlayer androidSpeechPlayer;
private InstructionListener instructionListener;
private Queue<VoiceInstructionMilestone> instructionQueue;
private boolean isMuted;

Expand Down Expand Up @@ -55,38 +54,22 @@ public void onDestroy() {
androidSpeechPlayer.onDestroy();
}

public void setInstructionListener(InstructionListener instructionListener) {
this.instructionListener = instructionListener;
}

@Override
public void onStart() {
if (instructionListener != null) {
instructionListener.onStart();
}

requestAudioFocus();
instructionQueue.remove();
}

@Override
public void onDone() {
if (instructionListener != null) {
instructionListener.onDone();
}

abandonAudioFocus();
}

@Override
public void onError(boolean isMapboxPlayer) {
if (instructionListener != null) {
instructionListener.onError(isMapboxPlayer);
}

if (isMapboxPlayer) { // If mapbox player failed, try android speech player
if (isMapboxPlayer) {
androidSpeechPlayer.play(instructionQueue.peek().getAnnouncement());
} else { // If android speech player fails, just drop the instruction
} else {
instructionQueue.remove();
}
}
Expand Down