use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.
the class WebOSTVService method displayMedia.
private void displayMedia(JSONObject params, final MediaPlayer.LaunchListener listener) {
String uri = "ssap://media.viewer/open";
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
JSONObject obj = (JSONObject) response;
LaunchSession launchSession = LaunchSession.launchSessionForAppId(obj.optString("id"));
launchSession.setService(WebOSTVService.this);
launchSession.setSessionId(obj.optString("sessionId"));
launchSession.setSessionType(LaunchSessionType.Media);
Util.postSuccess(listener, new MediaLaunchObject(launchSession, WebOSTVService.this));
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, params, true, responseListener);
request.send();
}
use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.
the class WebOSTVService method launchBrowser.
@Override
public void launchBrowser(String url, final Launcher.AppLaunchListener listener) {
String uri = "ssap://system.launcher/open";
JSONObject payload = new JSONObject();
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
JSONObject obj = (JSONObject) response;
LaunchSession launchSession = new LaunchSession();
launchSession.setService(WebOSTVService.this);
// note that response uses id to mean appId
launchSession.setAppId(obj.optString("id"));
launchSession.setSessionId(obj.optString("sessionId"));
launchSession.setSessionType(LaunchSessionType.App);
launchSession.setRawData(obj);
Util.postSuccess(listener, launchSession);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
try {
payload.put("target", url);
} catch (JSONException e) {
e.printStackTrace();
}
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, true, responseListener);
request.send();
}
use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.
the class CastService method launchWebApp.
@Override
public void launchWebApp(final String webAppId, final boolean relaunchIfRunning, final WebAppSession.LaunchListener listener) {
launchingAppId = webAppId;
final LaunchWebAppListener launchWebAppListener = new LaunchWebAppListener() {
@Override
public void onSuccess(WebAppSession webAppSession) {
Util.postSuccess(listener, webAppSession);
}
@Override
public void onFailure(ServiceCommandError error) {
Util.postError(listener, error);
}
};
ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void onConnected() {
// TODO Workaround, for some reason, if relaunchIfRunning is false, launchApplication returns 2005 error and cannot launch.
try {
if (relaunchIfRunning == false) {
Cast.CastApi.joinApplication(mApiClient).setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>() {
@Override
public void onResult(ApplicationConnectionResult result) {
if (result.getStatus().isSuccess() && result.getApplicationMetadata() != null && result.getApplicationMetadata().getName() != null && result.getApplicationMetadata().getApplicationId().equals(webAppId)) {
ApplicationMetadata applicationMetadata = result.getApplicationMetadata();
currentAppId = applicationMetadata.getApplicationId();
LaunchSession launchSession = LaunchSession.launchSessionForAppId(applicationMetadata.getApplicationId());
launchSession.setAppName(applicationMetadata.getName());
launchSession.setSessionId(result.getSessionId());
launchSession.setSessionType(LaunchSessionType.WebApp);
launchSession.setService(CastService.this);
CastWebAppSession webAppSession = new CastWebAppSession(launchSession, CastService.this);
webAppSession.setMetadata(applicationMetadata);
sessions.put(applicationMetadata.getApplicationId(), webAppSession);
Util.postSuccess(listener, webAppSession);
} else {
LaunchOptions options = new LaunchOptions();
options.setRelaunchIfRunning(true);
try {
Cast.CastApi.launchApplication(mApiClient, webAppId, options).setResultCallback(new ApplicationConnectionResultCallback(launchWebAppListener));
} catch (Exception e) {
Util.postError(listener, new ServiceCommandError(0, "Unable to launch", null));
}
}
}
});
} else {
LaunchOptions options = new LaunchOptions();
options.setRelaunchIfRunning(relaunchIfRunning);
Cast.CastApi.launchApplication(mApiClient, webAppId, options).setResultCallback(new ApplicationConnectionResultCallback(launchWebAppListener));
}
} catch (Exception e) {
Util.postError(listener, new ServiceCommandError(0, "Unable to launch", null));
}
}
};
runCommand(connectionListener);
}
use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.
the class CastService method joinWebApp.
@Override
public void joinWebApp(String webAppId, WebAppSession.LaunchListener listener) {
LaunchSession launchSession = LaunchSession.launchSessionForAppId(webAppId);
launchSession.setSessionType(LaunchSessionType.WebApp);
launchSession.setService(this);
joinWebApp(launchSession, listener);
}
use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.
the class DLNAService method decodeLaunchSession.
@Override
public LaunchSession decodeLaunchSession(String type, JSONObject sessionObj) throws JSONException {
if (type.equals("dlna")) {
LaunchSession launchSession = LaunchSession.launchSessionFromJSONObject(sessionObj);
launchSession.setService(this);
return launchSession;
}
return null;
}
Aggregations