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
protected void onStart() {
super.onStart();
if (controller != null) {
controller.release();
}
controller = newPlaybackController();
controller.init();
loadMediaInfo();

View File

@ -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);

View File

@ -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);