Only call getPSMPInfo if you need both the status and the playable.
Fixes AntennaPod/AntennaPod#942
This commit is contained in:
parent
e977b5fa54
commit
c2ca3e1bbd
@ -442,7 +442,7 @@ public class PlaybackService extends Service {
|
|||||||
}
|
}
|
||||||
writePlayerStatusPlaybackPreferences();
|
writePlayerStatusPlaybackPreferences();
|
||||||
|
|
||||||
final Playable playable = mediaPlayer.getPSMPInfo().playable;
|
final Playable playable = newInfo.playable;
|
||||||
|
|
||||||
// Gpodder: send play action
|
// Gpodder: send play action
|
||||||
if(GpodnetPreferences.loggedIn() && playable instanceof FeedMedia) {
|
if(GpodnetPreferences.loggedIn() && playable instanceof FeedMedia) {
|
||||||
@ -525,7 +525,7 @@ public class PlaybackService extends Service {
|
|||||||
public boolean onMediaPlayerError(Object inObj, int what, int extra) {
|
public boolean onMediaPlayerError(Object inObj, int what, int extra) {
|
||||||
final String TAG = "PlaybackService.onErrorListener";
|
final String TAG = "PlaybackService.onErrorListener";
|
||||||
Log.w(TAG, "An error has occured: " + what + " " + extra);
|
Log.w(TAG, "An error has occured: " + what + " " + extra);
|
||||||
if (mediaPlayer.getPSMPInfo().playerStatus == PlayerStatus.PLAYING) {
|
if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) {
|
||||||
mediaPlayer.pause(true, false);
|
mediaPlayer.pause(true, false);
|
||||||
}
|
}
|
||||||
sendNotificationBroadcast(NOTIFICATION_TYPE_ERROR, what);
|
sendNotificationBroadcast(NOTIFICATION_TYPE_ERROR, what);
|
||||||
@ -549,7 +549,7 @@ public class PlaybackService extends Service {
|
|||||||
private void endPlayback(boolean playNextEpisode) {
|
private void endPlayback(boolean playNextEpisode) {
|
||||||
Log.d(TAG, "Playback ended");
|
Log.d(TAG, "Playback ended");
|
||||||
|
|
||||||
final Playable playable = mediaPlayer.getPSMPInfo().playable;
|
final Playable playable = mediaPlayer.getPlayable();
|
||||||
if (playable == null) {
|
if (playable == null) {
|
||||||
Log.e(TAG, "Cannot end playback: media was null");
|
Log.e(TAG, "Cannot end playback: media was null");
|
||||||
return;
|
return;
|
||||||
@ -744,8 +744,7 @@ public class PlaybackService extends Service {
|
|||||||
|
|
||||||
SharedPreferences.Editor editor = PreferenceManager
|
SharedPreferences.Editor editor = PreferenceManager
|
||||||
.getDefaultSharedPreferences(getApplicationContext()).edit();
|
.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||||
PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo();
|
int playerStatus = getCurrentPlayerStatusAsInt(mediaPlayer.getPlayerStatus());
|
||||||
int playerStatus = getCurrentPlayerStatusAsInt(info.playerStatus);
|
|
||||||
|
|
||||||
editor.putInt(
|
editor.putInt(
|
||||||
PlaybackPreferences.PREF_CURRENT_PLAYER_STATUS, playerStatus);
|
PlaybackPreferences.PREF_CURRENT_PLAYER_STATUS, playerStatus);
|
||||||
@ -819,7 +818,7 @@ public class PlaybackService extends Service {
|
|||||||
if (mediaPlayer == null) {
|
if (mediaPlayer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlaybackServiceMediaPlayer.PSMPInfo newInfo = mediaPlayer.getPSMPInfo();
|
PlayerStatus playerStatus = mediaPlayer.getPlayerStatus();
|
||||||
final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext());
|
final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext());
|
||||||
|
|
||||||
if (!isCancelled() &&
|
if (!isCancelled() &&
|
||||||
@ -865,7 +864,7 @@ public class PlaybackService extends Service {
|
|||||||
.setLargeIcon(icon)
|
.setLargeIcon(icon)
|
||||||
.setSmallIcon(smallIcon)
|
.setSmallIcon(smallIcon)
|
||||||
.setPriority(UserPreferences.getNotifyPriority()); // set notification priority
|
.setPriority(UserPreferences.getNotifyPriority()); // set notification priority
|
||||||
if (newInfo.playerStatus == PlayerStatus.PLAYING) {
|
if (playerStatus == PlayerStatus.PLAYING) {
|
||||||
notificationBuilder.addAction(android.R.drawable.ic_media_pause, //pause action
|
notificationBuilder.addAction(android.R.drawable.ic_media_pause, //pause action
|
||||||
getString(R.string.pause_label),
|
getString(R.string.pause_label),
|
||||||
pauseButtonPendingIntent);
|
pauseButtonPendingIntent);
|
||||||
@ -923,7 +922,7 @@ public class PlaybackService extends Service {
|
|||||||
int position = getCurrentPosition();
|
int position = getCurrentPosition();
|
||||||
int duration = getDuration();
|
int duration = getDuration();
|
||||||
float playbackSpeed = getCurrentPlaybackSpeed();
|
float playbackSpeed = getCurrentPlaybackSpeed();
|
||||||
final Playable playable = mediaPlayer.getPSMPInfo().playable;
|
final Playable playable = mediaPlayer.getPlayable();
|
||||||
if (position != INVALID_TIME && duration != INVALID_TIME && playable != null) {
|
if (position != INVALID_TIME && duration != INVALID_TIME && playable != null) {
|
||||||
Log.d(TAG, "Saving current position to " + position);
|
Log.d(TAG, "Saving current position to " + position);
|
||||||
if (updatePlayedDuration && playable instanceof FeedMedia) {
|
if (updatePlayedDuration && playable instanceof FeedMedia) {
|
||||||
@ -1200,12 +1199,10 @@ public class PlaybackService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStatus getStatus() {
|
public PlayerStatus getStatus() {
|
||||||
return mediaPlayer.getPSMPInfo().playerStatus;
|
return mediaPlayer.getPlayerStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Playable getPlayable() {
|
public Playable getPlayable() { return mediaPlayer.getPlayable(); }
|
||||||
return mediaPlayer.getPSMPInfo().playable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpeed(float speed) {
|
public void setSpeed(float speed) {
|
||||||
mediaPlayer.setSpeed(speed);
|
mediaPlayer.setSpeed(speed);
|
||||||
@ -1231,7 +1228,7 @@ public class PlaybackService extends Service {
|
|||||||
public void seekTo(final int t) {
|
public void seekTo(final int t) {
|
||||||
if(mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING
|
if(mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING
|
||||||
&& GpodnetPreferences.loggedIn()) {
|
&& GpodnetPreferences.loggedIn()) {
|
||||||
final Playable playable = mediaPlayer.getPSMPInfo().playable;
|
final Playable playable = mediaPlayer.getPlayable();
|
||||||
if (playable instanceof FeedMedia) {
|
if (playable instanceof FeedMedia) {
|
||||||
FeedMedia media = (FeedMedia) playable;
|
FeedMedia media = (FeedMedia) playable;
|
||||||
FeedItem item = media.getItem();
|
FeedItem item = media.getItem();
|
||||||
|
@ -623,10 +623,6 @@ public class PlaybackServiceMediaPlayer {
|
|||||||
return mediaType;
|
return mediaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStatus getPlayerStatus() {
|
|
||||||
return playerStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStreaming() {
|
public boolean isStreaming() {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
@ -705,6 +701,26 @@ public class PlaybackServiceMediaPlayer {
|
|||||||
return new PSMPInfo(playerStatus, media);
|
return new PSMPInfo(playerStatus, media);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current status, if you need the media and the player status together, you should
|
||||||
|
* use getPSMPInfo() to make sure they're properly synchronized. Otherwise a race condition
|
||||||
|
* could result in nonsensical results (like a status of PLAYING, but a null playable)
|
||||||
|
* @return the current player status
|
||||||
|
*/
|
||||||
|
public PlayerStatus getPlayerStatus() {
|
||||||
|
return playerStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current media, if you need the media and the player status together, you should
|
||||||
|
* use getPSMPInfo() to make sure they're properly synchronized. Otherwise a race condition
|
||||||
|
* could result in nonsensical results (like a status of PLAYING, but a null playable)
|
||||||
|
* @return the current media. May be null
|
||||||
|
*/
|
||||||
|
public Playable getPlayable() {
|
||||||
|
return media;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a token to this object's MediaSession. The MediaSession should only be used for notifications
|
* Returns a token to this object's MediaSession. The MediaSession should only be used for notifications
|
||||||
* at the moment.
|
* at the moment.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user