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,7 +291,11 @@ public class RendererFragment extends Fragment implements
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
protected void eventReceived(GENASubscription sub) { protected void eventReceived(final GENASubscription sub) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, StateVariableValue> m = sub.getCurrentValues(); Map<String, StateVariableValue> m = sub.getCurrentValues();
try { try {
@ -296,39 +306,37 @@ public class RendererFragment extends Fragment implements
AVTransportVariable.TransportState.class) AVTransportVariable.TransportState.class)
.getValue()) { .getValue()) {
case PLAYING: case PLAYING:
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mPlayPause.setText(R.string.pause); mPlayPause.setText(R.string.pause);
mPlaying = true; mPlaying = true;
pollTimePosition(); pollTimePosition();
}
});
break; break;
case PAUSED_PLAYBACK:
// fallthrough
case STOPPED: case STOPPED:
getActivity().runOnUiThread(new Runnable() { if (!mManuallyStopped &&
(mPlaylist.size() > mCurrentTrack + 1)) {
@Override Log.d(TAG, "next");
public void run() { mManuallyStopped = false;
playTrack(mCurrentTrack +1);
break;
}
case PAUSED_PLAYBACK:
mManuallyStopped = false;
mPlayPause.setText(R.string.play); mPlayPause.setText(R.string.play);
mPlaying = false; mPlaying = false;
}
});
break; break;
default: default:
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.w(TAG, "Failed to parse UPNP event", e);
} }
} }
});
}
@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) {