Fixed widget if playbackservice is not running

This commit is contained in:
ByteHamster 2019-09-11 16:48:13 +02:00
parent ada0101b07
commit 93812f1b15

View File

@ -23,7 +23,9 @@ import com.bumptech.glide.request.RequestOptions;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.feed.MediaType;
import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.ApGlideSettings;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver;
import de.danoeh.antennapod.core.receiver.PlayerWidget; import de.danoeh.antennapod.core.receiver.PlayerWidget;
import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlaybackService;
@ -69,10 +71,8 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
} }
synchronized (waitUsingService) { synchronized (waitUsingService) {
if (playbackService != null) {
updateViews(); updateViews();
} }
}
if (playbackService != null) { if (playbackService != null) {
try { try {
@ -145,9 +145,12 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
String progressString; String progressString;
if (playbackService != null) { if (playbackService != null) {
progressString = getProgressString(playbackService.getCurrentPosition(), playbackService.getDuration()); progressString = getProgressString(playbackService.getCurrentPosition(),
playbackService.getDuration(), playbackService.getCurrentPlaybackSpeed());
} else { } else {
progressString = getProgressString(media.getPosition(), media.getDuration()); float speed = media.getMediaType() == MediaType.VIDEO ?
UserPreferences.getVideoPlaybackSpeed() : UserPreferences.getPlaybackSpeed();
progressString = getProgressString(media.getPosition(), media.getDuration(), speed);
} }
if (progressString != null) { if (progressString != null) {
@ -211,9 +214,9 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
return PendingIntent.getBroadcast(this, 0, startingIntent, 0); return PendingIntent.getBroadcast(this, 0, startingIntent, 0);
} }
private String getProgressString(int position, int duration) { private String getProgressString(int position, int duration, float speed) {
if (position > 0 && duration > 0) { if (position > 0 && duration > 0) {
TimeSpeedConverter converter = new TimeSpeedConverter(playbackService.getCurrentPlaybackSpeed()); TimeSpeedConverter converter = new TimeSpeedConverter(speed);
position = converter.convert(position); position = converter.convert(position);
duration = converter.convert(duration); duration = converter.convert(duration);
return Converter.getDurationStringLong(position) + " / " return Converter.getDurationStringLong(position) + " / "