Playbackservice now switches to next item in queue when completed
This commit is contained in:
parent
c8977b719f
commit
2ba267cb21
|
@ -546,6 +546,15 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
* sbPosition.getMax());
|
* sbPosition.getMax());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PlaybackService.NOTIFICATION_TYPE_RELOAD:
|
||||||
|
unbindService(mConnection);
|
||||||
|
if (positionObserver != null) {
|
||||||
|
positionObserver.cancel(true);
|
||||||
|
positionObserver = null;
|
||||||
|
}
|
||||||
|
mediaInfoLoaded = false;
|
||||||
|
bindToService();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -573,18 +582,20 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
protected Void doInBackground(MediaPlayer... p) {
|
protected Void doInBackground(MediaPlayer... p) {
|
||||||
Log.d(TAG, "Background Task started");
|
Log.d(TAG, "Background Task started");
|
||||||
player = p[0];
|
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");
|
Log.d(TAG, "Background Task finished");
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -209,7 +209,9 @@ public class FeedManager {
|
||||||
boolean removed = queue.remove(item);
|
boolean removed = queue.remove(item);
|
||||||
if (removed) {
|
if (removed) {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
|
adapter.open();
|
||||||
adapter.setQueue(queue);
|
adapter.setQueue(queue);
|
||||||
|
adapter.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +220,11 @@ public class FeedManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FeedItem getFirstQueueItem() {
|
public FeedItem getFirstQueueItem() {
|
||||||
return queue.get(0);
|
if (queue.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return queue.get(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNewFeed(Context context, Feed feed) {
|
private void addNewFeed(Context context, Feed feed) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import android.os.IBinder;
|
||||||
|
|
||||||
import de.podfetcher.PodcastApp;
|
import de.podfetcher.PodcastApp;
|
||||||
import de.podfetcher.activity.MediaplayerActivity;
|
import de.podfetcher.activity.MediaplayerActivity;
|
||||||
|
import de.podfetcher.feed.FeedItem;
|
||||||
import de.podfetcher.feed.FeedMedia;
|
import de.podfetcher.feed.FeedMedia;
|
||||||
import de.podfetcher.feed.Feed;
|
import de.podfetcher.feed.Feed;
|
||||||
import de.podfetcher.feed.FeedManager;
|
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_ERROR = 0;
|
||||||
public static final int NOTIFICATION_TYPE_INFO = 1;
|
public static final int NOTIFICATION_TYPE_INFO = 1;
|
||||||
public static final int NOTIFICATION_TYPE_BUFFER_UPDATE = 2;
|
public static final int NOTIFICATION_TYPE_BUFFER_UPDATE = 2;
|
||||||
|
public static final int NOTIFICATION_TYPE_RELOAD = 3;
|
||||||
|
|
||||||
|
|
||||||
/** Is true if service is running. */
|
/** Is true if service is running. */
|
||||||
|
@ -382,8 +384,21 @@ public class PlaybackService extends Service {
|
||||||
manager.removeQueueItem(PlaybackService.this, media.getItem());
|
manager.removeQueueItem(PlaybackService.this, media.getItem());
|
||||||
}
|
}
|
||||||
manager.setFeedMedia(PlaybackService.this, media);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue