use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method connectToApp.
/* Connect to a native/installed webOS app */
public void connectToApp(String appId, final WebAppSession.LaunchListener listener) {
LaunchSession launchSession = LaunchSession.launchSessionForAppId(appId);
launchSession.setSessionType(LaunchSessionType.App);
launchSession.setService(this);
final WebOSWebAppSession webAppSession = webAppSessionForLaunchSession(launchSession);
connectToWebApp(webAppSession, false, new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
Util.postSuccess(listener, webAppSession);
}
});
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class CastService method getPlayState.
@Override
public void getPlayState(PlayStateListener listener) {
if (mMediaPlayer != null && mMediaPlayer.getMediaStatus() != null) {
PlayStateStatus status = PlayStateStatus.convertPlayerStateToPlayStateStatus(mMediaPlayer.getMediaStatus().getPlayerState());
Util.postSuccess(listener, status);
} else {
Util.postError(listener, new ServiceCommandError(0, "There is no media currently available", null));
}
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class CastService method playMedia.
private void playMedia(final com.google.android.gms.cast.MediaInfo mediaInformation, final String mediaAppId, final LaunchListener listener) {
final ApplicationConnectionResultCallback webAppLaunchCallback = new ApplicationConnectionResultCallback(new LaunchWebAppListener() {
@Override
public void onSuccess(final WebAppSession webAppSession) {
ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void onConnected() {
try {
mMediaPlayer.load(mApiClient, mediaInformation, true).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
@Override
public void onResult(MediaChannelResult result) {
Status status = result.getStatus();
if (status.isSuccess()) {
webAppSession.launchSession.setSessionType(LaunchSessionType.Media);
// White text, black outline, no background
TextTrackStyle textTrackStyle = new TextTrackStyle();
textTrackStyle.setForegroundColor(Color.parseColor("#FFFFFFFF"));
textTrackStyle.setBackgroundColor(Color.parseColor("#01000000"));
textTrackStyle.setWindowType(TextTrackStyle.WINDOW_TYPE_NONE);
textTrackStyle.setEdgeType(TextTrackStyle.EDGE_TYPE_OUTLINE);
textTrackStyle.setEdgeColor(Color.BLACK);
textTrackStyle.setFontGenericFamily(TextTrackStyle.FONT_FAMILY_SANS_SERIF);
mMediaPlayer.setTextTrackStyle(mApiClient, textTrackStyle);
mMediaPlayer.setActiveMediaTracks(mApiClient, new long[] { 1 });
Util.postSuccess(listener, new MediaLaunchObject(webAppSession.launchSession, CastService.this));
} else {
Util.postError(listener, new ServiceCommandError(status.getStatusCode(), status.getStatusMessage(), status));
}
}
});
} catch (Exception e) {
Util.postError(listener, new ServiceCommandError(0, "Unable to load", null));
}
}
};
runCommand(connectionListener);
}
@Override
public void onFailure(ServiceCommandError error) {
Util.postError(listener, error);
}
});
launchingAppId = mediaAppId;
ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void onConnected() {
boolean relaunchIfRunning = false;
try {
if (Cast.CastApi.getApplicationStatus(mApiClient) == null || (!mediaAppId.equals(currentAppId))) {
relaunchIfRunning = true;
}
LaunchOptions options = new LaunchOptions();
options.setRelaunchIfRunning(relaunchIfRunning);
Cast.CastApi.launchApplication(mApiClient, mediaAppId, options).setResultCallback(webAppLaunchCallback);
} catch (Exception e) {
Util.postError(listener, new ServiceCommandError(0, "Unable to launch", null));
}
}
};
runCommand(connectionListener);
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class CastService method seek.
@Override
public void seek(final long position, final ResponseListener<Object> listener) {
if (mMediaPlayer == null || mMediaPlayer.getMediaStatus() == null) {
Util.postError(listener, new ServiceCommandError(0, "There is no media currently available", null));
return;
}
ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void onConnected() {
try {
mMediaPlayer.seek(mApiClient, position, RemoteMediaPlayer.RESUME_STATE_UNCHANGED).setResultCallback(new ResultCallback<MediaChannelResult>() {
@Override
public void onResult(MediaChannelResult result) {
Status status = result.getStatus();
if (status.isSuccess()) {
Util.postSuccess(listener, null);
} else {
Util.postError(listener, new ServiceCommandError(status.getStatusCode(), status.getStatusMessage(), status));
}
}
});
} catch (Exception e) {
Util.postError(listener, new ServiceCommandError(0, "Unable to seek", null));
}
}
};
runCommand(connectionListener);
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method joinWebApp.
@Override
public void joinWebApp(final LaunchSession webAppLaunchSession, final WebAppSession.LaunchListener listener) {
final WebOSWebAppSession webAppSession = this.webAppSessionForLaunchSession(webAppLaunchSession);
webAppSession.join(new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
Util.postSuccess(listener, webAppSession);
}
});
}
Aggregations