Autoplay next file on playlist after finishing.

This commit is contained in:
Felix Ableitner 2013-06-09 20:25:42 +02:00
parent 3a3e14c850
commit c0608b0d0d

View file

@ -78,6 +78,12 @@ public class RendererFragment extends Fragment implements
private int mCurrentTrack; private int mCurrentTrack;
/**
* Used to determine when the player stops due to the media file being
* over (so the next one can be played).
*/
private boolean mManuallyStopped;
private List<Item> mPlaylist; private List<Item> mPlaylist;
/** /**
@ -285,50 +291,52 @@ public class RendererFragment extends Fragment implements
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
protected void eventReceived(GENASubscription sub) { protected void eventReceived(final GENASubscription sub) {
@SuppressWarnings("unchecked") getActivity().runOnUiThread(new Runnable() {
Map<String, StateVariableValue> m = sub.getCurrentValues();
try { @Override
LastChange lastChange = new LastChange( public void run() {
new AVTransportLastChangeParser(), @SuppressWarnings("unchecked")
m.get("LastChange").toString()); Map<String, StateVariableValue> m = sub.getCurrentValues();
switch (lastChange.getEventedValue(0, try {
AVTransportVariable.TransportState.class) LastChange lastChange = new LastChange(
.getValue()) { new AVTransportLastChangeParser(),
case PLAYING: m.get("LastChange").toString());
getActivity().runOnUiThread(new Runnable() { switch (lastChange.getEventedValue(0,
AVTransportVariable.TransportState.class)
@Override .getValue()) {
public void run() { case PLAYING:
mPlayPause.setText(R.string.pause); mPlayPause.setText(R.string.pause);
mPlaying = true; mPlaying = true;
pollTimePosition(); pollTimePosition();
} break;
}); case STOPPED:
break; if (!mManuallyStopped &&
case PAUSED_PLAYBACK: (mPlaylist.size() > mCurrentTrack + 1)) {
// fallthrough Log.d(TAG, "next");
case STOPPED: mManuallyStopped = false;
getActivity().runOnUiThread(new Runnable() { playTrack(mCurrentTrack +1);
break;
@Override }
public void run() { case PAUSED_PLAYBACK:
mManuallyStopped = false;
mPlayPause.setText(R.string.play); mPlayPause.setText(R.string.play);
mPlaying = false; mPlaying = false;
} break;
}); default:
break; }
default:
} } catch (Exception e) {
Log.w(TAG, "Failed to parse UPNP event", e);
} catch (Exception e) { }
e.printStackTrace(); }
} });
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
protected void eventsMissed(GENASubscription sub, int numberOfMissedEvents) { protected void eventsMissed(GENASubscription sub,
int numberOfMissedEvents) {
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@ -402,11 +410,11 @@ public class RendererFragment extends Fragment implements
break; break;
case R.id.previous: case R.id.previous:
if (mCurrentTrack != 0 && !mPlaylist.isEmpty()) if (mCurrentTrack != 0 && !mPlaylist.isEmpty())
playTrack(--mCurrentTrack); playTrack(mCurrentTrack - 1);
break; break;
case R.id.next: case R.id.next:
if (mPlaylist.size() > mCurrentTrack + 1) if (mPlaylist.size() > mCurrentTrack + 1)
playTrack(++mCurrentTrack); playTrack(mCurrentTrack + 1);
break; break;
} }
} }
@ -415,6 +423,7 @@ public class RendererFragment extends Fragment implements
* Sends 'pause' signal to current renderer. * Sends 'pause' signal to current renderer.
*/ */
private void pause() { private void pause() {
mManuallyStopped = true;
final Service<?, ?> service = getService("AVTransport"); final Service<?, ?> service = getService("AVTransport");
mUpnpService.getControlPoint().execute(new Stop(service) { mUpnpService.getControlPoint().execute(new Stop(service) {