Bugfix: MediaPlayer creation might fail for ttsFallback.
Seen on a Fairphone 4.
Part of
@@ -126,10 +126,14 @@ public class VoiceAnnouncement {
}
if (ttsFallback == null) {
ttsFallback = MediaPlayer.create(context, R.raw.tts_fallback);
+ if (ttsFallback == null) {
+ Log.w(TAG, "MediaPlayer for ttsFallback could not be created.");
+ } else {
ttsFallback.setAudioStreamType(AUDIO_STREAM);
ttsFallback.setLooping(false);
}
}
+ }
public void announce(@NonNull Track track) {
synchronized (this) {
@@ -148,9 +152,13 @@ public class VoiceAnnouncement {
}
if (!ttsReady) {
+ if (ttsFallback == null) {
+ Log.w(TAG, "MediaPlayer for ttsFallback was not created.");
+ } else {
Log.i(TAG, "TTS not ready/available, just generating a tone.");
ttsFallback.seekTo(0);
ttsFallback.start();
+ }
return;
}
