From 2fca491f53e4cdc7bbe1ed0ed019d48c7cfc9cf1 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 17 Apr 2019 20:52:13 +0200 Subject: [PATCH] Made sure that there is not an ANR when switching media player --- .../core/service/playback/PlaybackServiceFlavorHelper.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/play/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceFlavorHelper.java b/core/src/play/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceFlavorHelper.java index 85c8a22f5..15675c966 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceFlavorHelper.java +++ b/core/src/play/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceFlavorHelper.java @@ -20,6 +20,8 @@ import com.google.android.gms.cast.ApplicationMetadata; import com.google.android.libraries.cast.companionlibrary.cast.BaseCastManager; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import de.danoeh.antennapod.core.cast.CastConsumer; import de.danoeh.antennapod.core.cast.CastManager; @@ -188,8 +190,8 @@ public class PlaybackServiceFlavorHelper { PlaybackServiceMediaPlayer mediaPlayer = callback.getMediaPlayer(); if (mediaPlayer != null) { try { - mediaPlayer.stopPlayback(false).get(); - } catch (InterruptedException | ExecutionException e) { + mediaPlayer.stopPlayback(false).get(2, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { Log.e(TAG, "There was a problem stopping playback while switching media players", e); } mediaPlayer.shutdownQuietly();