From 8ebc98af13233b61637bbee868306149dec92f04 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 12 Apr 2019 11:50:57 +0200 Subject: [PATCH] Fixed crash when re-using released controller --- .../de/danoeh/antennapod/activity/MediaplayerActivity.java | 3 --- .../de/danoeh/antennapod/fragment/ExternalPlayerFragment.java | 4 +++- .../danoeh/antennapod/fragment/ItemDescriptionFragment.java | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index aaab579a2..86d4ec642 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -278,9 +278,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements @Override protected void onStart() { super.onStart(); - if (controller != null) { - controller.release(); - } controller = newPlaybackController(); controller.init(); loadMediaInfo(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index 2c35bdba4..508659f65 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -143,6 +143,7 @@ public class ExternalPlayerFragment extends Fragment { @Override public void onStart() { super.onStart(); + controller = setupPlaybackController(); controller.init(); EventBus.getDefault().register(this); } @@ -152,6 +153,7 @@ public class ExternalPlayerFragment extends Fragment { super.onStop(); if (controller != null) { controller.release(); + controller = null; } EventBus.getDefault().unregister(this); } @@ -233,7 +235,7 @@ public class ExternalPlayerFragment extends Fragment { .into(imgvCover); fragmentLayout.setVisibility(View.VISIBLE); - if (controller.isPlayingVideoLocally()) { + if (controller != null && controller.isPlayingVideoLocally()) { butPlay.setVisibility(View.GONE); } else { butPlay.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index 27ffb0a70..9cee59531 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -251,7 +251,7 @@ public class ItemDescriptionFragment extends Fragment { SharedPreferences prefs = getActivity().getSharedPreferences(PREF, Activity.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); - if (controller.getMedia() != null && webvDescription != null) { + if (controller != null && controller.getMedia() != null && webvDescription != null) { Log.d(TAG, "Saving scroll position: " + webvDescription.getScrollY()); editor.putInt(PREF_SCROLL_Y, webvDescription.getScrollY()); editor.putString(PREF_PLAYABLE_ID, controller.getMedia().getIdentifier() @@ -272,7 +272,7 @@ public class ItemDescriptionFragment extends Fragment { PREF, Activity.MODE_PRIVATE); String id = prefs.getString(PREF_PLAYABLE_ID, ""); int scrollY = prefs.getInt(PREF_SCROLL_Y, -1); - if (scrollY != -1 && controller.getMedia() != null + if (controller != null && scrollY != -1 && controller.getMedia() != null && id.equals(controller.getMedia().getIdentifier().toString()) && webvDescription != null) { Log.d(TAG, "Restored scroll Position: " + scrollY);