Autoplay next file on playlist after finishing.
This commit is contained in:
parent
3a3e14c850
commit
c0608b0d0d
1 changed files with 47 additions and 38 deletions
|
@ -78,6 +78,12 @@ public class RendererFragment extends Fragment implements
|
|||
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -285,7 +291,11 @@ public class RendererFragment extends Fragment implements
|
|||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
protected void eventReceived(GENASubscription sub) {
|
||||
protected void eventReceived(final GENASubscription sub) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, StateVariableValue> m = sub.getCurrentValues();
|
||||
try {
|
||||
|
@ -296,39 +306,37 @@ public class RendererFragment extends Fragment implements
|
|||
AVTransportVariable.TransportState.class)
|
||||
.getValue()) {
|
||||
case PLAYING:
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mPlayPause.setText(R.string.pause);
|
||||
mPlaying = true;
|
||||
pollTimePosition();
|
||||
}
|
||||
});
|
||||
break;
|
||||
case PAUSED_PLAYBACK:
|
||||
// fallthrough
|
||||
case STOPPED:
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mManuallyStopped &&
|
||||
(mPlaylist.size() > mCurrentTrack + 1)) {
|
||||
Log.d(TAG, "next");
|
||||
mManuallyStopped = false;
|
||||
playTrack(mCurrentTrack +1);
|
||||
break;
|
||||
}
|
||||
case PAUSED_PLAYBACK:
|
||||
mManuallyStopped = false;
|
||||
mPlayPause.setText(R.string.play);
|
||||
mPlaying = false;
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.w(TAG, "Failed to parse UPNP event", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
protected void eventsMissed(GENASubscription sub, int numberOfMissedEvents) {
|
||||
protected void eventsMissed(GENASubscription sub,
|
||||
int numberOfMissedEvents) {
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
@ -402,11 +410,11 @@ public class RendererFragment extends Fragment implements
|
|||
break;
|
||||
case R.id.previous:
|
||||
if (mCurrentTrack != 0 && !mPlaylist.isEmpty())
|
||||
playTrack(--mCurrentTrack);
|
||||
playTrack(mCurrentTrack - 1);
|
||||
break;
|
||||
case R.id.next:
|
||||
if (mPlaylist.size() > mCurrentTrack + 1)
|
||||
playTrack(++mCurrentTrack);
|
||||
playTrack(mCurrentTrack + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -415,6 +423,7 @@ public class RendererFragment extends Fragment implements
|
|||
* Sends 'pause' signal to current renderer.
|
||||
*/
|
||||
private void pause() {
|
||||
mManuallyStopped = true;
|
||||
final Service<?, ?> service = getService("AVTransport");
|
||||
mUpnpService.getControlPoint().execute(new Stop(service) {
|
||||
|
||||
|
|
Reference in a new issue