Skip to content

Commit

Permalink
Added more intelligent routing of media control commands in NetcastTV…
Browse files Browse the repository at this point in the history
…Service
  • Loading branch information
Jeremy White committed Jun 12, 2014
1 parent cb7990b commit c998b54
Showing 1 changed file with 65 additions and 14 deletions.
79 changes: 65 additions & 14 deletions src/com/connectsdk/service/NetcastTVService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,27 @@ public CapabilityPriorityLevel getMediaPlayerCapabilityLevel() {
@Override
public void displayImage(final String url, final String mimeType, final String title, final String description, final String iconSrc, final MediaPlayer.LaunchListener listener) {
if ( dlnaService != null ) {
dlnaService.displayImage(url, mimeType, title, description, iconSrc, listener);
final MediaPlayer.LaunchListener launchListener = new LaunchListener() {

@Override
public void onError(ServiceCommandError error) {
if (listener != null)
Util.postError(listener, error);
}

@Override
public void onSuccess(MediaLaunchObject object) {
object.launchSession.setAppId("SmartShareª");
object.launchSession.setAppName("SmartShareª");

object.mediaControl = NetcastTVService.this.getMediaControl();

if (listener != null)
Util.postSuccess(listener, object);
}
};

dlnaService.displayImage(url, mimeType, title, description, iconSrc, launchListener);
}
else {
System.err.println("DLNA Service is not ready yet");
Expand All @@ -1443,7 +1463,27 @@ public void displayImage(final String url, final String mimeType, final String t
@Override
public void playMedia(final String url, final String mimeType, final String title, final String description, final String iconSrc, final boolean shouldLoop, final MediaPlayer.LaunchListener listener) {
if ( dlnaService != null ) {
dlnaService.playMedia(url, mimeType, title, description, iconSrc, shouldLoop, listener);
final MediaPlayer.LaunchListener launchListener = new LaunchListener() {

@Override
public void onError(ServiceCommandError error) {
if (listener != null)
Util.postError(listener, error);
}

@Override
public void onSuccess(MediaLaunchObject object) {
object.launchSession.setAppId("SmartShareª");
object.launchSession.setAppName("SmartShareª");

object.mediaControl = NetcastTVService.this.getMediaControl();

if (listener != null)
Util.postSuccess(listener, object);
}
};

dlnaService.playMedia(url, mimeType, title, description, iconSrc, shouldLoop, launchListener);
}
else {
System.err.println("DLNA Service is not ready yet");
Expand All @@ -1465,7 +1505,10 @@ public void closeMedia(LaunchSession launchSession, ResponseListener<Object> lis
*****************/
@Override
public MediaControl getMediaControl() {
return this;
if (DiscoveryManager.getInstance().getPairingLevel() == PairingLevel.OFF)
return this.dlnaService;
else
return this;
};

@Override
Expand Down Expand Up @@ -1502,23 +1545,42 @@ public void fastForward(ResponseListener<Object> listener) {
public void seek(long position, ResponseListener<Object> listener) {
if ( dlnaService != null ) {
dlnaService.seek(position, listener);
} else {
if (listener != null)
Util.postError(listener, new ServiceCommandError(-1, "Command is not supported", null));
}
}

@Override
public void getDuration(DurationListener listener) {
if ( dlnaService != null ) {
dlnaService.getDuration(listener);
} else {
if (listener != null)
Util.postError(listener, new ServiceCommandError(-1, "Command is not supported", null));
}
}

@Override
public void getPosition(PositionListener listener) {
if ( dlnaService != null ) {
dlnaService.getPosition(listener);
} else {
if (listener != null)
Util.postError(listener, new ServiceCommandError(-1, "Command is not supported", null));
}
}

@Override
public void getPlayState(PlayStateListener listener) {
Util.postError(listener, ServiceCommandError.notSupported());
}

@Override
public ServiceSubscription<PlayStateListener> subscribePlayState(PlayStateListener listener) {
Util.postError(listener, ServiceCommandError.notSupported());
return null;
}

/**************
MOUSE CONTROL
Expand Down Expand Up @@ -2217,15 +2279,4 @@ protected void updateCapabilities() {

setCapabilities(capabilities);
}

@Override
public void getPlayState(PlayStateListener listener) {
Util.postError(listener, ServiceCommandError.notSupported());
}

@Override
public ServiceSubscription<PlayStateListener> subscribePlayState(PlayStateListener listener) {
Util.postError(listener, ServiceCommandError.notSupported());
return null;
}
}

0 comments on commit c998b54

Please sign in to comment.