Fixed crash when re-using released controller

This commit is contained in:
ByteHamster 2019-04-12 11:50:57 +02:00
parent 3f1e6b5d50
commit 8ebc98af13
3 changed files with 5 additions and 6 deletions

View File

@ -278,9 +278,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
if (controller != null) {
controller.release();
}
controller = newPlaybackController(); controller = newPlaybackController();
controller.init(); controller.init();
loadMediaInfo(); loadMediaInfo();

View File

@ -143,6 +143,7 @@ public class ExternalPlayerFragment extends Fragment {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
controller = setupPlaybackController();
controller.init(); controller.init();
EventBus.getDefault().register(this); EventBus.getDefault().register(this);
} }
@ -152,6 +153,7 @@ public class ExternalPlayerFragment extends Fragment {
super.onStop(); super.onStop();
if (controller != null) { if (controller != null) {
controller.release(); controller.release();
controller = null;
} }
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
} }
@ -233,7 +235,7 @@ public class ExternalPlayerFragment extends Fragment {
.into(imgvCover); .into(imgvCover);
fragmentLayout.setVisibility(View.VISIBLE); fragmentLayout.setVisibility(View.VISIBLE);
if (controller.isPlayingVideoLocally()) { if (controller != null && controller.isPlayingVideoLocally()) {
butPlay.setVisibility(View.GONE); butPlay.setVisibility(View.GONE);
} else { } else {
butPlay.setVisibility(View.VISIBLE); butPlay.setVisibility(View.VISIBLE);

View File

@ -251,7 +251,7 @@ public class ItemDescriptionFragment extends Fragment {
SharedPreferences prefs = getActivity().getSharedPreferences(PREF, SharedPreferences prefs = getActivity().getSharedPreferences(PREF,
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit(); 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()); Log.d(TAG, "Saving scroll position: " + webvDescription.getScrollY());
editor.putInt(PREF_SCROLL_Y, webvDescription.getScrollY()); editor.putInt(PREF_SCROLL_Y, webvDescription.getScrollY());
editor.putString(PREF_PLAYABLE_ID, controller.getMedia().getIdentifier() editor.putString(PREF_PLAYABLE_ID, controller.getMedia().getIdentifier()
@ -272,7 +272,7 @@ public class ItemDescriptionFragment extends Fragment {
PREF, Activity.MODE_PRIVATE); PREF, Activity.MODE_PRIVATE);
String id = prefs.getString(PREF_PLAYABLE_ID, ""); String id = prefs.getString(PREF_PLAYABLE_ID, "");
int scrollY = prefs.getInt(PREF_SCROLL_Y, -1); 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()) && id.equals(controller.getMedia().getIdentifier().toString())
&& webvDescription != null) { && webvDescription != null) {
Log.d(TAG, "Restored scroll Position: " + scrollY); Log.d(TAG, "Restored scroll Position: " + scrollY);