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,18 +582,20 @@ 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);
} catch (InterruptedException e) {
Log.d(TAG,
"Thread was interrupted while waiting. Finishing now");
return null;
}
publishProgress();
while (player.isPlaying() && !isCancelled()) {
try {
Thread.sleep(WAITING_INTERVALL);
} catch (InterruptedException e) {
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,7 +220,11 @@ public class FeedManager {
}
public FeedItem getFirstQueueItem() {
return queue.get(0);
if (queue.isEmpty()) {
return null;
} else {
return queue.get(0);
}
}
private void addNewFeed(Context context, Feed 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);
setStatus(PlayerStatus.STOPPED);
stopForeground(true);
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);
}
}
};