Prevent NPE

This commit is contained in:
Martin Fietz 2016-02-23 08:27:09 +01:00
parent b1df272797
commit 4366e134cf
2 changed files with 17 additions and 5 deletions

View File

@ -139,8 +139,10 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(drawerToggle != null) {
drawerToggle.onConfigurationChanged(newConfig);
}
}
private void loadLastFragment() {
Log.d(TAG, "Restoring instance state");
@ -283,7 +285,10 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
}
public void notifyMediaPositionChanged() {
ChaptersFragment chaptersFragment = mPagerAdapter.getChaptersFragment();
if(pagerAdapter == null) {
return;
}
ChaptersFragment chaptersFragment = pagerAdapter.getChaptersFragment();
if(chaptersFragment != null) {
ChaptersListAdapter adapter = (ChaptersListAdapter) chaptersFragment.getListAdapter();
if (adapter != null) {

View File

@ -206,9 +206,11 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
@Override
protected void onPause() {
super.onPause();
if(controller != null) {
controller.reinitServiceIfPaused();
controller.pause();
}
}
/**
* Should be used to switch to another player activity if the mime type is
@ -582,8 +584,10 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
super.onResume();
Log.d(TAG, "onResume()");
StorageUtils.checkStorageAvailability(this);
if(controller != null) {
controller.init();
}
}
/**
* Called by 'handleStatus()' when the PlaybackService is waiting for
@ -618,6 +622,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
private void updateProgressbarPosition(int position, int duration) {
Log.d(TAG, "updateProgressbarPosition(" + position + ", " + duration + ")");
if(sbPosition == null) {
return;
}
float progress = ((float) position) / duration;
sbPosition.setProgress((int) (progress * sbPosition.getMax()));
}