summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2021-10-24 12:33:45 +0200
committerByteHamster <info@bytehamster.com>2021-10-24 12:45:23 +0200
commit0eeb47ee1e2ad4d2f91c1851480af80fcc364181 (patch)
treec2e6127f3ed72eae9bf4e05d10e1c568572feb93 /core
parente734d43e7287a0f0f3f678c5875a34bf6bc75716 (diff)
downloadAntennaPod-0eeb47ee1e2ad4d2f91c1851480af80fcc364181.zip
Show actual error messages instead of just the error codes
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/event/PlayerErrorEvent.java13
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java12
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java12
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java25
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java26
-rw-r--r--core/src/main/res/values/strings.xml1
7 files changed, 41 insertions, 50 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/event/PlayerErrorEvent.java b/core/src/main/java/de/danoeh/antennapod/core/event/PlayerErrorEvent.java
new file mode 100644
index 000000000..2fb27e958
--- /dev/null
+++ b/core/src/main/java/de/danoeh/antennapod/core/event/PlayerErrorEvent.java
@@ -0,0 +1,13 @@
+package de.danoeh.antennapod.core.event;
+
+public class PlayerErrorEvent {
+ private final String message;
+
+ public PlayerErrorEvent(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java
index 0a9bf5f43..30e76787d 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java
@@ -5,6 +5,8 @@ import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import android.view.SurfaceHolder;
+import androidx.annotation.NonNull;
+import androidx.core.util.Consumer;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.DefaultRenderersFactory;
@@ -54,7 +56,7 @@ public class ExoPlayerWrapper implements IPlayer {
private MediaSource mediaSource;
private MediaPlayer.OnSeekCompleteListener audioSeekCompleteListener;
private MediaPlayer.OnCompletionListener audioCompletionListener;
- private MediaPlayer.OnErrorListener audioErrorListener;
+ private Consumer<String> audioErrorListener;
private MediaPlayer.OnBufferingUpdateListener bufferingUpdateListener;
private PlaybackParameters playbackParameters;
private MediaPlayer.OnInfoListener infoListener;
@@ -98,9 +100,11 @@ public class ExoPlayerWrapper implements IPlayer {
}
@Override
- public void onPlayerError(ExoPlaybackException error) {
+ public void onPlayerError(@NonNull ExoPlaybackException error) {
if (audioErrorListener != null) {
- audioErrorListener.onError(null, error.type + ERROR_CODE_OFFSET, 0);
+ Throwable cause = error.getCause();
+ audioErrorListener.accept(cause != null
+ ? cause.getLocalizedMessage() : error.getLocalizedMessage());
}
}
@@ -323,7 +327,7 @@ public class ExoPlayerWrapper implements IPlayer {
this.audioSeekCompleteListener = audioSeekCompleteListener;
}
- void setOnErrorListener(MediaPlayer.OnErrorListener audioErrorListener) {
+ void setOnErrorListener(Consumer<String> audioErrorListener) {
this.audioErrorListener = audioErrorListener;
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java
index f74e3b9ad..90b3b6ae2 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java
@@ -14,7 +14,9 @@ import android.view.SurfaceHolder;
import androidx.media.AudioAttributesCompat;
import androidx.media.AudioFocusRequestCompat;
import androidx.media.AudioManagerCompat;
+import de.danoeh.antennapod.core.event.PlayerErrorEvent;
import de.danoeh.antennapod.core.storage.DBReader;
+import de.danoeh.antennapod.core.util.playback.MediaPlayerError;
import org.antennapod.audio.MediaPlayer;
import java.io.File;
@@ -41,6 +43,7 @@ import de.danoeh.antennapod.core.util.playback.IPlayer;
import de.danoeh.antennapod.model.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
import de.danoeh.antennapod.core.util.playback.VideoPlayer;
+import org.greenrobot.eventbus.EventBus;
/**
* Manages the MediaPlayer object of the PlaybackService.
@@ -294,6 +297,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
} catch (IOException | IllegalStateException e) {
e.printStackTrace();
setPlayerStatus(PlayerStatus.ERROR, null);
+ EventBus.getDefault().postSticky(new PlayerErrorEvent(e.getLocalizedMessage()));
}
}
@@ -402,6 +406,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
} catch (IOException e) {
e.printStackTrace();
setPlayerStatus(PlayerStatus.ERROR, null);
+ EventBus.getDefault().postSticky(new PlayerErrorEvent(e.getLocalizedMessage()));
}
}
playerLock.unlock();
@@ -734,7 +739,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
ap.setOnErrorListener((mediaPlayer, i, i1) -> true);
} else if (mediaPlayer instanceof ExoPlayerWrapper) {
ExoPlayerWrapper ap = (ExoPlayerWrapper) mediaPlayer;
- ap.setOnErrorListener((mediaPlayer, i, i1) -> true);
+ ap.setOnErrorListener(message -> { });
}
}
@@ -1033,7 +1038,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
ap.setOnCompletionListener(audioCompletionListener);
ap.setOnSeekCompleteListener(audioSeekCompleteListener);
ap.setOnBufferingUpdateListener(audioBufferingUpdateListener);
- ap.setOnErrorListener(audioErrorListener);
+ ap.setOnErrorListener(message -> EventBus.getDefault().postSticky(new PlayerErrorEvent(message)));
ap.setOnInfoListener(audioInfoListener);
} else {
Log.w(TAG, "Unknown media player: " + mp);
@@ -1084,7 +1089,8 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
private final android.media.MediaPlayer.OnErrorListener videoErrorListener = this::genericOnError;
private boolean genericOnError(Object inObj, int what, int extra) {
- return callback.onMediaPlayerError(inObj, what, extra);
+ EventBus.getDefault().postSticky(new PlayerErrorEvent(MediaPlayerError.getErrorString(context, what)));
+ return true;
}
private final MediaPlayer.OnSeekCompleteListener audioSeekCompleteListener =
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
index d1dcd463a..49a4fb021 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
@@ -43,6 +43,7 @@ import androidx.core.app.NotificationManagerCompat;
import androidx.media.MediaBrowserServiceCompat;
import androidx.preference.PreferenceManager;
+import de.danoeh.antennapod.core.event.PlayerErrorEvent;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
@@ -161,7 +162,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
public static final int EXTRA_CODE_VIDEO = 2;
public static final int EXTRA_CODE_CAST = 3;
- public static final int NOTIFICATION_TYPE_ERROR = 0;
public static final int NOTIFICATION_TYPE_BUFFER_UPDATE = 2;
/**
@@ -939,19 +939,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
@Override
- public boolean onMediaPlayerError(Object inObj, int what, int extra) {
- final String TAG = "PlaybackSvc.onErrorLtsn";
- Log.w(TAG, "An error has occured: " + what + " " + extra);
- if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) {
- mediaPlayer.pause(true, false);
- }
- sendNotificationBroadcast(NOTIFICATION_TYPE_ERROR, what);
- PlaybackPreferences.writeNoMediaPlaying();
- stateManager.stopService();
- return true;
- }
-
- @Override
public void onPostPlayback(@NonNull Playable media, boolean ended, boolean skipped,
boolean playingNext) {
PlaybackService.this.onPostPlayback(media, ended, skipped, playingNext);
@@ -996,6 +983,16 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
};
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ @SuppressWarnings("unused")
+ public void playerError(PlayerErrorEvent event) {
+ if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) {
+ mediaPlayer.pause(true, false);
+ }
+ PlaybackPreferences.writeNoMediaPlaying();
+ stateManager.stopService();
+ }
+
private Playable getNextInQueue(final Playable currentMedia) {
if (!(currentMedia instanceof FeedMedia)) {
Log.d(TAG, "getNextInQueue(), but playable not an instance of FeedMedia, so not proceeding");
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java
index e093383b9..2aeb84cb0 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java
@@ -356,8 +356,6 @@ public abstract class PlaybackServiceMediaPlayer {
boolean onMediaPlayerInfo(int code, @StringRes int resourceId);
- boolean onMediaPlayerError(Object inObj, int what, int extra);
-
void onPostPlayback(@NonNull Playable media, boolean ended, boolean skipped, boolean playingNext);
void onPlaybackStart(@NonNull Playable playable, int position);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java
index 7f4c1ceaf..ec74b2fe3 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java
@@ -7,14 +7,11 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
-import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;
import android.util.Pair;
import android.view.SurfaceHolder;
import androidx.annotation.NonNull;
-import de.danoeh.antennapod.core.R;
-import de.danoeh.antennapod.core.event.MessageEvent;
import de.danoeh.antennapod.core.event.ServiceEvent;
import de.danoeh.antennapod.model.playback.MediaType;
import de.danoeh.antennapod.core.feed.util.PlaybackSpeedUtils;
@@ -209,9 +206,6 @@ public abstract class PlaybackController {
return;
}
switch (type) {
- case PlaybackService.NOTIFICATION_TYPE_ERROR:
- handleError(code);
- break;
case PlaybackService.NOTIFICATION_TYPE_BUFFER_UPDATE:
float progress = ((float) code) / 100;
onBufferUpdate(progress);
@@ -264,8 +258,6 @@ public abstract class PlaybackController {
public void onSleepTimerUpdate() {}
- public void handleError(int code) {}
-
public void onPlaybackEnd() {}
/**
@@ -276,10 +268,6 @@ public abstract class PlaybackController {
Log.d(TAG, "status: " + status.toString());
checkMediaInfoLoaded();
switch (status) {
- case ERROR:
- EventBus.getDefault().post(new MessageEvent(activity.getString(R.string.player_error_msg)));
- handleError(MediaPlayer.MEDIA_ERROR_UNKNOWN);
- break;
case PAUSED:
onPositionObserverUpdate();
updatePlayButtonShowsPlay(true);
@@ -555,20 +543,6 @@ public abstract class PlaybackController {
}
}
- /**
- * Move service into INITIALIZED state if it's paused to save bandwidth
- */
- public void reinitServiceIfPaused() {
- if (playbackService != null
- && playbackService.isStreaming()
- && !PlaybackService.isCasting()
- && (playbackService.getStatus() == PlayerStatus.PAUSED ||
- (playbackService.getStatus() == PlayerStatus.PREPARING &&
- !playbackService.isStartWhenPrepared()))) {
- playbackService.reinit();
- }
- }
-
public boolean isStreaming() {
return playbackService != null && playbackService.isStreaming();
}
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index 5d86109c3..804bf7af8 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -295,7 +295,6 @@
<string name="confirm_mobile_download_dialog_enable_temporarily">Allow temporarily</string>
<!-- Mediaplayer messages -->
- <string name="player_error_msg">Error!</string>
<string name="playback_error_server_died">Server died</string>
<string name="playback_error_unsupported">Unsupported media type</string>
<string name="playback_error_timeout">Operation timed out</string>