Search in sources :

Example 21 with ServiceCommandError

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();
}
Also used : JSONObject(org.json.JSONObject) LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 22 with ServiceCommandError

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);
            }
        });
    }
}
Also used : JSONObject(org.json.JSONObject) WebAppSession(com.connectsdk.service.sessions.WebAppSession) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) MediaPlayer(com.connectsdk.service.capability.MediaPlayer)

Example 23 with ServiceCommandError

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;
}
Also used : ProgramInfo(com.connectsdk.core.ProgramInfo) JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 24 with ServiceCommandError

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;
}
Also used : ProgramList(com.connectsdk.core.ProgramList) JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ChannelInfo(com.connectsdk.core.ChannelInfo) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 25 with ServiceCommandError

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();
}
Also used : JSONObject(org.json.JSONObject) LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Aggregations

ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)84 JSONObject (org.json.JSONObject)70 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)65 ServiceCommand (com.connectsdk.service.command.ServiceCommand)55 JSONException (org.json.JSONException)47 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)13 IOException (java.io.IOException)13 LaunchSession (com.connectsdk.service.sessions.LaunchSession)12 AppInfo (com.connectsdk.core.AppInfo)11 SuppressLint (android.annotation.SuppressLint)8 JSONArray (org.json.JSONArray)7 WebOSWebAppSession (com.connectsdk.service.sessions.WebOSWebAppSession)6 ChannelInfo (com.connectsdk.core.ChannelInfo)5 HttpConnection (com.connectsdk.etc.helper.HttpConnection)4 WebAppSession (com.connectsdk.service.sessions.WebAppSession)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 MediaInfo (com.connectsdk.core.MediaInfo)3 MediaPlayer (com.connectsdk.service.capability.MediaPlayer)3