Do not crash if mediaPlayer is null

This commit is contained in:
ByteHamster 2018-09-26 17:13:56 +02:00
parent 819d2df8ed
commit 33674625b4
2 changed files with 8 additions and 2 deletions

View File

@ -41,8 +41,8 @@ public class PlayerWidgetJobService extends JobIntentService {
return; return;
} }
if (PlaybackService.isRunning && playbackService == null) { synchronized (waitForService) {
synchronized (waitForService) { if (PlaybackService.isRunning && playbackService == null) {
bindService(new Intent(this, PlaybackService.class), mConnection, 0); bindService(new Intent(this, PlaybackService.class), mConnection, 0);
while (playbackService == null) { while (playbackService == null) {
try { try {

View File

@ -1680,6 +1680,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
* an invalid state. * an invalid state.
*/ */
public int getDuration() { public int getDuration() {
if (mediaPlayer == null) {
return INVALID_TIME;
}
return mediaPlayer.getDuration(); return mediaPlayer.getDuration();
} }
@ -1688,6 +1691,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
* is in an invalid state. * is in an invalid state.
*/ */
public int getCurrentPosition() { public int getCurrentPosition() {
if (mediaPlayer == null) {
return INVALID_TIME;
}
return mediaPlayer.getPosition(); return mediaPlayer.getPosition();
} }