Merge pull request #3110 from ByteHamster/fix-controller-release-crash

Fixed crash when re-using released controller
This commit is contained in:
H. Lehmann 2019-04-12 23:11:12 +02:00 committed by GitHub
commit 48b2a67a72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);