Playbackservice now switches to next item in queue when completed

This commit is contained in:
daniel oeh 2012-07-03 12:11:46 +02:00
parent c8977b719f
commit 2ba267cb21
3 changed files with 45 additions and 13 deletions

View File

@ -546,6 +546,15 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
* sbPosition.getMax());
}
break;
case PlaybackService.NOTIFICATION_TYPE_RELOAD:
unbindService(mConnection);
if (positionObserver != null) {
positionObserver.cancel(true);
positionObserver = null;
}
mediaInfoLoaded = false;
bindToService();
break;
}
} else {
@ -573,7 +582,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
protected Void doInBackground(MediaPlayer... p) {
Log.d(TAG, "Background Task started");
player = p[0];
try {
while (player.isPlaying() && !isCancelled()) {
try {
Thread.sleep(WAITING_INTERVALL);
@ -581,10 +590,12 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
Log.d(TAG,
"Thread was interrupted while waiting. Finishing now");
return null;
} catch (IllegalStateException e) {
Log.d(TAG, "player is in illegal state, exiting now");
}
publishProgress();
}
} catch (IllegalStateException e) {
Log.d(TAG, "player is in illegal state, exiting now");
}
Log.d(TAG, "Background Task finished");
return null;

View File

@ -209,7 +209,9 @@ public class FeedManager {
boolean removed = queue.remove(item);
if (removed) {
PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.setQueue(queue);
adapter.close();
}
}
@ -218,8 +220,12 @@ public class FeedManager {
}
public FeedItem getFirstQueueItem() {
if (queue.isEmpty()) {
return null;
} else {
return queue.get(0);
}
}
private void addNewFeed(Context context, Feed feed) {
feeds.add(feed);

View File

@ -27,6 +27,7 @@ import android.os.IBinder;
import de.podfetcher.PodcastApp;
import de.podfetcher.activity.MediaplayerActivity;
import de.podfetcher.feed.FeedItem;
import de.podfetcher.feed.FeedMedia;
import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedManager;
@ -64,6 +65,7 @@ public class PlaybackService extends Service {
public static final int NOTIFICATION_TYPE_ERROR = 0;
public static final int NOTIFICATION_TYPE_INFO = 1;
public static final int NOTIFICATION_TYPE_BUFFER_UPDATE = 2;
public static final int NOTIFICATION_TYPE_RELOAD = 3;
/** Is true if service is running. */
@ -382,8 +384,21 @@ public class PlaybackService extends Service {
manager.removeQueueItem(PlaybackService.this, media.getItem());
}
manager.setFeedMedia(PlaybackService.this, media);
FeedItem nextItem = manager.getFirstQueueItem();
if (nextItem == null) {
Log.d(TAG, "No more items in queue");
setStatus(PlayerStatus.STOPPED);
stopForeground(true);
} else {
Log.d(TAG, "Loading next item in queue");
media = nextItem.getMedia();
feed = nextItem.getFeed();
shouldStream = !media.isDownloaded();
resetVideoSurface();
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
}
}
};