Fixed possible nullpointerexception in onPositionObserverUpdate()

This commit is contained in:
daniel oeh 2012-09-26 21:21:04 +02:00
parent 258a6acd6e
commit 891f2e09f4
1 changed files with 15 additions and 12 deletions

View File

@ -317,18 +317,21 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
protected abstract void clearStatusMsg();
protected void onPositionObserverUpdate() {
int currentPosition = controller.getPosition();
int duration = controller.getDuration();
if (currentPosition != PlaybackService.INVALID_TIME
&& duration != PlaybackService.INVALID_TIME) {
controller.getMedia().setPosition(currentPosition);
txtvPosition.setText(Converter
.getDurationStringLong(currentPosition));
txtvLength.setText(Converter.getDurationStringLong(duration));
updateProgressbarPosition(currentPosition, duration);
} else {
Log.w(TAG,
"Could not react to position observer update because of invalid time");
if (controller != null) {
int currentPosition = controller.getPosition();
int duration = controller.getDuration();
if (currentPosition != PlaybackService.INVALID_TIME
&& duration != PlaybackService.INVALID_TIME
&& controller.getMedia() != null) {
controller.getMedia().setPosition(currentPosition);
txtvPosition.setText(Converter
.getDurationStringLong(currentPosition));
txtvLength.setText(Converter.getDurationStringLong(duration));
updateProgressbarPosition(currentPosition, duration);
} else {
Log.w(TAG,
"Could not react to position observer update because of invalid time");
}
}
}