Made sure that there is not an ANR when switching media player

This commit is contained in:
ByteHamster 2019-04-17 20:52:13 +02:00
parent 09e7f60db8
commit 2fca491f53
1 changed files with 4 additions and 2 deletions

View File

@ -20,6 +20,8 @@ import com.google.android.gms.cast.ApplicationMetadata;
import com.google.android.libraries.cast.companionlibrary.cast.BaseCastManager; import com.google.android.libraries.cast.companionlibrary.cast.BaseCastManager;
import java.util.concurrent.ExecutionException; 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.CastConsumer;
import de.danoeh.antennapod.core.cast.CastManager; import de.danoeh.antennapod.core.cast.CastManager;
@ -188,8 +190,8 @@ public class PlaybackServiceFlavorHelper {
PlaybackServiceMediaPlayer mediaPlayer = callback.getMediaPlayer(); PlaybackServiceMediaPlayer mediaPlayer = callback.getMediaPlayer();
if (mediaPlayer != null) { if (mediaPlayer != null) {
try { try {
mediaPlayer.stopPlayback(false).get(); mediaPlayer.stopPlayback(false).get(2, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException | TimeoutException e) {
Log.e(TAG, "There was a problem stopping playback while switching media players", e); Log.e(TAG, "There was a problem stopping playback while switching media players", e);
} }
mediaPlayer.shutdownQuietly(); mediaPlayer.shutdownQuietly();