Implemented skip functionality

This commit is contained in:
daniel oeh 2013-03-07 20:02:23 +01:00
parent 3e25aa4ea3
commit 5876b98bb8
7 changed files with 115 additions and 46 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
<item android:id="@id/skip_episode_item" android:title="@string/skip_episode_label" android:showAsAction="collapseActionView"></item><item
android:id="@+id/download_item"
android:icon="?attr/av_download"
android:showAsAction="ifRoom"
@ -68,4 +68,5 @@
android:title="@string/support_label">
</item>
</menu>

View File

@ -1,7 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/disable_sleeptimer_item" android:icon="?attr/device_access_time" android:title="@string/sleep_timer_label" android:showAsAction="always"></item><item android:id="@+id/set_sleeptimer_item" android:showAsAction="collapseActionView" android:title="@string/set_sleeptimer_label"></item><item
<item
android:id="@+id/disable_sleeptimer_item"
android:icon="?attr/device_access_time"
android:showAsAction="always"
android:title="@string/sleep_timer_label">
</item>
<item
android:id="@+id/set_sleeptimer_item"
android:showAsAction="collapseActionView"
android:title="@string/set_sleeptimer_label">
</item>
<item
android:id="@+id/share_link_item"
android:showAsAction="collapseActionView"
android:title="@string/share_link_label">
@ -19,7 +30,10 @@
android:title="@string/support_label"
android:visible="false">
</item>
<item
android:id="@id/skip_episode_item"
android:showAsAction="collapseActionView"
android:title="@string/skip_episode_label"
android:visible="true"/>
</menu>

View File

@ -14,5 +14,6 @@
<item name="share_url_item" type="id"/>
<item name="organize_queue_item" type="id"/>
<item name="drag_handle" type="id"/>
<item name="skip_episode_item" type="id"/>
</resources>

View File

@ -70,6 +70,7 @@
<string name="support_label">Flattr this</string>
<string name="enqueue_all_new">Enqueue all</string>
<string name="download_all">Download all</string>
<string name="skip_episode_label">Skip episode</string>
<!-- Download messages and labels -->
<string name="download_successful">Download successful</string>

View File

@ -227,7 +227,7 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
media != null && media.getWebsiteLink() != null);
menu.findItem(R.id.visit_website_item).setVisible(
media != null && media.getWebsiteLink() != null);
menu.findItem(R.id.skip_episode_item).setVisible(media != null);
boolean sleepTimerSet = controller.sleepTimerActive();
boolean sleepTimerNotSet = controller.sleepTimerNotActive();
menu.findItem(R.id.set_sleeptimer_item).setVisible(sleepTimerNotSet);
@ -303,6 +303,10 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
case R.id.share_link_item:
ShareUtils.shareLink(this, media.getWebsiteLink());
break;
case R.id.skip_episode_item:
sendBroadcast(new Intent(
PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
break;
default:
return false;

View File

@ -85,6 +85,12 @@ public class PlaybackService extends Service {
*/
public static final String ACTION_SHUTDOWN_PLAYBACK_SERVICE = "action.de.danoeh.antennapod.service.actionShutdownPlaybackService";
/**
* If the PlaybackService receives this action, it will end playback of the
* current episode and load the next episode if there is one available.
* */
public static final String ACTION_SKIP_CURRENT_EPISODE = "action.de.danoeh.antennapod.service.skipCurrentEpisode";
/** Used in NOTIFICATION_TYPE_RELOAD. */
public static final int EXTRA_CODE_AUDIO = 1;
public static final int EXTRA_CODE_VIDEO = 2;
@ -266,6 +272,7 @@ public class PlaybackService extends Service {
ACTION_SHUTDOWN_PLAYBACK_SERVICE));
registerReceiver(audioBecomingNoisy, new IntentFilter(
AudioManager.ACTION_AUDIO_BECOMING_NOISY));
registerReceiver(skipCurrentEpisodeReceiver, new IntentFilter(ACTION_SKIP_CURRENT_EPISODE));
}
@ -296,6 +303,7 @@ public class PlaybackService extends Service {
unregisterReceiver(headsetDisconnected);
unregisterReceiver(shutdownReceiver);
unregisterReceiver(audioBecomingNoisy);
unregisterReceiver(skipCurrentEpisodeReceiver);
if (android.os.Build.VERSION.SDK_INT >= 14) {
audioManager.unregisterRemoteControlClient(remoteControlClient);
}
@ -460,10 +468,12 @@ public class PlaybackService extends Service {
@Override
protected void onPostExecute(Playable result) {
if (status == PlayerStatus.INITIALIZING) {
if (result != null) {
try {
if (shouldStream) {
player.setDataSource(media.getStreamUrl());
player.setDataSource(media
.getStreamUrl());
setStatus(PlayerStatus.PREPARING);
player.prepareAsync();
} else {
@ -481,6 +491,7 @@ public class PlaybackService extends Service {
ACTION_SHUTDOWN_PLAYBACK_SERVICE));
}
}
}
@Override
protected void onPreExecute() {
@ -531,11 +542,16 @@ public class PlaybackService extends Service {
@Override
protected void onPostExecute(Playable result) {
// check if state of service has changed. If it has
// changed, assume that loaded metadata is not needed
// anymore.
if (status == PlayerStatus.INITIALIZING) {
if (result != null) {
playingVideo = false;
try {
if (shouldStream) {
player.setDataSource(media.getStreamUrl());
player.setDataSource(media
.getStreamUrl());
} else if (media.localFileAvailable()) {
player.setDataSource(media
.getLocalMediaUrl());
@ -561,6 +577,11 @@ public class PlaybackService extends Service {
sendBroadcast(new Intent(
ACTION_SHUTDOWN_PLAYBACK_SERVICE));
}
} else {
if (AppConfig.DEBUG)
Log.d(TAG,
"Status of player has changed during initialization. Stopping init process.");
}
}
@Override
@ -688,7 +709,7 @@ public class PlaybackService extends Service {
private void endPlayback(boolean playNextEpisode) {
if (AppConfig.DEBUG)
Log.d(TAG, "Playback completed");
Log.d(TAG, "Playback ended");
audioManager.abandonAudioFocus(audioFocusChangeListener);
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
@ -1214,6 +1235,22 @@ public class PlaybackService extends Service {
};
private BroadcastReceiver skipCurrentEpisodeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_SKIP_CURRENT_EPISODE)) {
if (AppConfig.DEBUG)
Log.d(TAG, "Received SKIP_CURRENT_EPISODE intent");
if (media != null) {
setStatus(PlayerStatus.STOPPED);
player.reset();
endPlayback(false);
}
}
}
};
/** Periodically saves the position of the media file */
class PositionSaver implements Runnable {
public static final int WAITING_INTERVALL = 5000;

View File

@ -7,6 +7,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.service.PlaybackService;
import de.danoeh.antennapod.storage.DownloadRequestException;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.ShareUtils;
@ -55,16 +56,22 @@ public class FeedItemMenuHandler {
&& requester.isDownloadingFile(selectedItem.getMedia());
boolean notLoadedAndNotLoading = hasMedia && (!downloaded)
&& (!downloading);
boolean isPlaying = hasMedia
&& selectedItem.getState() == FeedItem.State.PLAYING;
FeedItem.State state = selectedItem.getState();
if (!downloaded) {
if (!isPlaying) {
mi.setItemVisibility(R.id.skip_episode_item, false);
}
if (!downloaded || isPlaying) {
mi.setItemVisibility(R.id.play_item, false);
mi.setItemVisibility(R.id.remove_item, false);
}
if (!notLoadedAndNotLoading) {
mi.setItemVisibility(R.id.download_item, false);
}
if (!(notLoadedAndNotLoading | downloading)) {
if (!(notLoadedAndNotLoading | downloading | isPlaying)) {
mi.setItemVisibility(R.id.stream_item, false);
}
if (!downloading) {
@ -104,6 +111,10 @@ public class FeedItemMenuHandler {
DownloadRequester requester = DownloadRequester.getInstance();
FeedManager manager = FeedManager.getInstance();
switch (menuItemId) {
case R.id.skip_episode_item:
context.sendBroadcast(new Intent(
PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
break;
case R.id.download_item:
manager.downloadFeedItem(context, selectedItem);
break;