Fixed playback to gmediarenderer.

Calling stop before play fixes the otherwise buggy playback.
This commit is contained in:
Felix Ableitner 2014-04-13 11:38:05 +02:00
parent 635bdb04d3
commit 2997938e18

View file

@ -77,6 +77,7 @@ public class RemotePlayServiceBinder extends IRemotePlayService.Stub {
private RemotePlayService mRps;
private boolean mStartingPlayback = false;
public RemotePlayServiceBinder(RemotePlayService rps) {
mRps = rps;
}
@ -118,7 +119,7 @@ public class RemotePlayServiceBinder extends IRemotePlayService.Stub {
LastChange lastChange = new LastChange(
new AVTransportLastChangeParser(),
m.get("LastChange").toString());
if (lastChange.getEventedValue(0,
if (mStartingPlayback || lastChange.getEventedValue(0,
AVTransportVariable.TransportState.class) == null)
return;
@ -203,29 +204,48 @@ public class RemotePlayServiceBinder extends IRemotePlayService.Stub {
* current renderer.
*/
@Override
public void play(String uri, String metadata) throws RemoteException {
public void play(final String uri, final String metadata) throws RemoteException {
mStartingPlayback = true;
mPlaybackState = MediaItemStatus.PLAYBACK_STATE_BUFFERING;
mRps.mUpnpService.getControlPoint().execute(new SetAVTransportURI(
mRps.getService(mCurrentRenderer, "AVTransport"),
uri, metadata) {
mRps.mUpnpService.getControlPoint().execute(
new Stop(mRps.getService(mCurrentRenderer, "AVTransport")) {
@SuppressWarnings("rawtypes")
@Override
public void failure(ActionInvocation invocation,
UpnpResponse operation, String defaultMsg) {
Log.w(TAG, "Set URI failed: " + defaultMsg);
mRps.sendError("Set URI failed: " + defaultMsg);
org.teleal.cling.model.message.UpnpResponse operation,
String defaultMessage) {
Log.w(TAG, "Stop failed: " + defaultMessage);
mRps.sendError("Stop failed: " + defaultMessage);
mStartingPlayback = false;
}
@SuppressWarnings("rawtypes")
@Override
public void success(ActionInvocation invocation) {
mRps.mUpnpService.getControlPoint().execute(new SetAVTransportURI(
mRps.getService(mCurrentRenderer, "AVTransport"),
uri, metadata) {
@Override
public void failure(ActionInvocation invocation,
UpnpResponse operation, String defaultMsg) {
Log.w(TAG, "Set URI failed: " + defaultMsg);
mRps.sendError("Set URI failed: " + defaultMsg);
mStartingPlayback = false;
}
@Override
public void success(ActionInvocation invocation) {
// Can't use resume here as we don't have the session id to call.
mRps.mUpnpService.getControlPoint().execute(
new Play(mRps.getService(mCurrentRenderer,
"AVTransport")) {
@Override
public void success(ActionInvocation invocation) {
Log.d(TAG, "play success");
mPlaybackState = MediaItemStatus.PLAYBACK_STATE_PLAYING;
mStartingPlayback = false;
}
@Override
@ -233,11 +253,15 @@ public class RemotePlayServiceBinder extends IRemotePlayService.Stub {
UpnpResponse operation, String defaultMessage) {
Log.w(TAG, "Play failed: " + defaultMessage);
mRps.sendError("Play failed: " + defaultMessage);
mStartingPlayback = false;
}
});
}
});
}
});
}
/**
* Pauses playback on current renderer.