Direct play from the lists

subsequent play of the next feed item from the queue now works
This commit is contained in:
volhol 2015-04-02 19:54:04 +02:00
parent 247ef778aa
commit 42e118626e
5 changed files with 57 additions and 21 deletions

View File

@ -51,7 +51,7 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
if (item.hasMedia() && item.getMedia().isCurrentlyPlaying()) {
context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
}
else if (item.hasMedia() && item.getMedia().isPlaying()) {
else if (item.hasMedia() && item.getMedia().isCurrentlyPaused()) {
context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE));
}
else {

View File

@ -129,10 +129,20 @@ public class FeedMedia extends FeedFile implements Playable {
/**
* Reads playback preferences to determine whether this FeedMedia object is
* currently being played and the player status is playing.
* currently being played and the current player status is playing.
*/
public boolean isCurrentlyPlaying() {
return isPlaying() && PlaybackPreferences.getPlayerStatusIsPlaying();
return isPlaying() &&
((PlaybackPreferences.getCurrentPlayerStatus() == PlaybackPreferences.PLAYER_STATUS_PLAYING));
}
/**
* Reads playback preferences to determine whether this FeedMedia object is
* currently being played and the current player status is paused.
*/
public boolean isCurrentlyPaused() {
return isPlaying() &&
((PlaybackPreferences.getCurrentPlayerStatus() == PlaybackPreferences.PLAYER_STATUS_PAUSED));
}

View File

@ -44,18 +44,27 @@ public class PlaybackPreferences implements
/** True if last played media was a video. */
public static final String PREF_CURRENT_EPISODE_IS_VIDEO = "de.danoeh.antennapod.preferences.lastIsVideo";
/** True if player status is playing. */
public static final String PREF_PLAYER_STATUS_IS_PLAYING = "de.danoeh.antennapod.preferences.playerStatusIsPlaying";
/** The current player status as int. */
public static final String PREF_CURRENT_PLAYER_STATUS = "de.danoeh.antennapod.preferences.currentPlayerStatus";
/** Value of PREF_CURRENTLY_PLAYING_MEDIA if no media is playing. */
public static final long NO_MEDIA_PLAYING = -1;
/** Value of PREF_CURRENT_PLAYER_STATUS if media player status is playing. */
public static final int PLAYER_STATUS_PLAYING = 1;
/** Value of PREF_CURRENT_PLAYER_STATUS if media player status is paused. */
public static final int PLAYER_STATUS_PAUSED = 2;
/** Value of PREF_CURRENT_PLAYER_STATUS if media player status is neither playing nor paused. */
public static final int PLAYER_STATUS_OTHER = 3;
private long currentlyPlayingFeedId;
private long currentlyPlayingFeedMediaId;
private long currentlyPlayingMedia;
private boolean currentEpisodeIsStream;
private boolean currentEpisodeIsVideo;
private boolean playerStatusIsPlaying;
private int currentPlayerStatus;
private static PlaybackPreferences instance;
private Context context;
@ -92,7 +101,8 @@ public class PlaybackPreferences implements
NO_MEDIA_PLAYING);
currentEpisodeIsStream = sp.getBoolean(PREF_CURRENT_EPISODE_IS_STREAM, true);
currentEpisodeIsVideo = sp.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false);
playerStatusIsPlaying = sp.getBoolean(PREF_PLAYER_STATUS_IS_PLAYING, false);
currentPlayerStatus = sp.getInt(PREF_CURRENT_PLAYER_STATUS,
PLAYER_STATUS_OTHER);
}
@Override
@ -115,9 +125,9 @@ public class PlaybackPreferences implements
currentlyPlayingFeedMediaId = sp.getLong(
PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING);
}
else if (key.equals(PREF_PLAYER_STATUS_IS_PLAYING)) {
playerStatusIsPlaying = sp.getBoolean(
PREF_PLAYER_STATUS_IS_PLAYING, false);
else if (key.equals(PREF_CURRENT_PLAYER_STATUS)) {
currentPlayerStatus = sp.getInt(PREF_CURRENT_PLAYER_STATUS,
PLAYER_STATUS_OTHER);
EventDistributor.getInstance().sendPlayerStatusUpdateBroadcast();
}
}
@ -154,9 +164,9 @@ public class PlaybackPreferences implements
return instance.currentEpisodeIsVideo;
}
public static boolean getPlayerStatusIsPlaying() {
public static int getCurrentPlayerStatus() {
instanceAvailable();
return instance.playerStatusIsPlaying;
return instance.currentPlayerStatus;
}

View File

@ -653,11 +653,26 @@ public class PlaybackService extends Service {
editor.putLong(
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID,
PlaybackPreferences.NO_MEDIA_PLAYING);
editor.putBoolean(
PlaybackPreferences.PREF_PLAYER_STATUS_IS_PLAYING, false);
editor.putInt(
PlaybackPreferences.PREF_CURRENT_PLAYER_STATUS,
PlaybackPreferences.PLAYER_STATUS_OTHER);
editor.commit();
}
private int getCurrentPlayerStatusAsInt(PlayerStatus playerStatus) {
int playerStatusAsInt;
switch (playerStatus) {
case PLAYING:
playerStatusAsInt = PlaybackPreferences.PLAYER_STATUS_PLAYING;
break;
case PAUSED:
playerStatusAsInt = PlaybackPreferences.PLAYER_STATUS_PAUSED;
break;
default:
playerStatusAsInt = PlaybackPreferences.PLAYER_STATUS_OTHER;
}
return playerStatusAsInt;
}
private void writePlaybackPreferences() {
if (BuildConfig.DEBUG)
@ -668,7 +683,7 @@ public class PlaybackService extends Service {
PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo();
MediaType mediaType = mediaPlayer.getCurrentMediaType();
boolean stream = mediaPlayer.isStreaming();
boolean isPlaying = (info.playerStatus == PlayerStatus.PLAYING);
int playerStatus = getCurrentPlayerStatusAsInt(info.playerStatus);
if (info.playable != null) {
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA,
@ -705,8 +720,8 @@ public class PlaybackService extends Service {
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID,
PlaybackPreferences.NO_MEDIA_PLAYING);
}
editor.putBoolean(
PlaybackPreferences.PREF_PLAYER_STATUS_IS_PLAYING, isPlaying);
editor.putInt(
PlaybackPreferences.PREF_CURRENT_PLAYER_STATUS, playerStatus);
editor.commit();
}
@ -718,10 +733,10 @@ public class PlaybackService extends Service {
SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext()).edit();
PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo();
boolean isPlaying = (info.playerStatus == PlayerStatus.PLAYING);
int playerStatus = getCurrentPlayerStatusAsInt(info.playerStatus);
editor.putBoolean(
PlaybackPreferences.PREF_PLAYER_STATUS_IS_PLAYING, isPlaying);
editor.putInt(
PlaybackPreferences.PREF_CURRENT_PLAYER_STATUS, playerStatus);
editor.commit();
}

View File

@ -169,7 +169,8 @@ public class PlaybackServiceMediaPlayer {
if (media != null) {
if (!forceReset && media.getIdentifier().equals(playable.getIdentifier())) {
if (!forceReset && media.getIdentifier().equals(playable.getIdentifier())
&& playerStatus == PlayerStatus.PLAYING) {
// episode is already playing -> ignore method call
if (BuildConfig.DEBUG)
Log.d(TAG, "Method call to playMediaObject was ignored: media file already playing.");