use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method launchAppWithInfo.
@Override
public void launchAppWithInfo(final AppInfo appInfo, Object params, final Launcher.AppLaunchListener listener) {
String uri = "ssap://system.launcher/launch";
JSONObject payload = new JSONObject();
final String appId = appInfo.getId();
String contentId = null;
if (params != null) {
try {
contentId = (String) ((JSONObject) params).get("contentId");
} catch (JSONException e) {
e.printStackTrace();
}
}
try {
payload.put("id", appId);
if (contentId != null)
payload.put("contentId", contentId);
if (params != null)
payload.put("params", params);
} catch (JSONException e) {
e.printStackTrace();
}
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(appId);
launchSession.setSessionId(obj.optString("sessionId"));
launchSession.setSessionType(LaunchSessionType.App);
Util.postSuccess(listener, launchSession);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, true, responseListener);
request.send();
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method playMedia.
@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 ("4.0.0".equalsIgnoreCase(this.serviceDescription.getVersion())) {
DeviceService dlnaService = this.getDLNAService();
if (dlnaService != null) {
MediaPlayer mediaPlayer = dlnaService.getAPI(MediaPlayer.class);
if (mediaPlayer != null) {
mediaPlayer.playMedia(url, mimeType, title, description, iconSrc, shouldLoop, listener);
return;
}
}
JSONObject params = null;
try {
params = new JSONObject() {
{
put("target", url);
put("title", title == null ? NULL : title);
put("description", description == null ? NULL : description);
put("mimeType", mimeType == null ? NULL : mimeType);
put("iconSrc", iconSrc == null ? NULL : iconSrc);
put("loop", shouldLoop);
}
};
} catch (JSONException ex) {
ex.printStackTrace();
Util.postError(listener, new ServiceCommandError(-1, ex.getLocalizedMessage(), ex));
}
if (params != null)
this.displayMedia(params, listener);
} else {
final WebAppSession.LaunchListener webAppLaunchListener = new WebAppSession.LaunchListener() {
@Override
public void onError(ServiceCommandError error) {
listener.onError(error);
}
@Override
public void onSuccess(WebAppSession webAppSession) {
webAppSession.playMedia(url, mimeType, title, description, iconSrc, shouldLoop, listener);
}
};
this.getWebAppLauncher().joinWebApp(MEDIA_PLAYER_ID, new WebAppSession.LaunchListener() {
@Override
public void onError(ServiceCommandError error) {
getWebAppLauncher().launchWebApp(MEDIA_PLAYER_ID, webAppLaunchListener);
}
@Override
public void onSuccess(WebAppSession webAppSession) {
webAppSession.playMedia(url, mimeType, title, description, iconSrc, shouldLoop, listener);
}
});
}
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method getChannelCurrentProgramInfo.
private ServiceCommand<ResponseListener<Object>> getChannelCurrentProgramInfo(boolean isSubscription, final ProgramInfoListener listener) {
String uri = "ssap://tv/getChannelCurrentProgramInfo";
ServiceCommand<ResponseListener<Object>> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
JSONObject jsonObj = (JSONObject) response;
ProgramInfo programInfo = parseRawProgramInfo(jsonObj);
Util.postSuccess(listener, programInfo);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription)
request = new URLServiceSubscription<ResponseListener<Object>>(this, uri, null, true, responseListener);
else
request = new ServiceCommand<ResponseListener<Object>>(this, uri, null, true, responseListener);
request.send();
return request;
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method getProgramList.
private ServiceCommand<ResponseListener<Object>> getProgramList(boolean isSubscription, final ProgramListListener listener) {
ServiceCommand<ResponseListener<Object>> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
try {
JSONObject jsonObj = (JSONObject) response;
JSONObject jsonChannel = (JSONObject) jsonObj.get("channel");
ChannelInfo channel = parseRawChannelData(jsonChannel);
JSONArray programList = (JSONArray) jsonObj.get("programList");
Util.postSuccess(listener, new ProgramList(channel, programList));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription)
request = new URLServiceSubscription<ResponseListener<Object>>(this, PROGRAM, null, true, responseListener);
else
request = new ServiceCommand<ResponseListener<Object>>(this, PROGRAM, null, true, responseListener);
request.send();
return request;
}
use of com.connectsdk.service.command.ServiceCommandError 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();
}
Aggregations