Search in sources :

Example 81 with ServiceCommandError

use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.

the class WebOSWebAppSession method getPlayState.

@Override
public void getPlayState(final PlayStateListener listener) {
    int requestIdNumber = getNextId();
    final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
    JSONObject message = null;
    try {
        message = new JSONObject() {

            {
                put("contentType", namespaceKey + "mediaCommand");
                put("mediaCommand", new JSONObject() {

                    {
                        put("type", "getPlayState");
                        put("requestId", requestId);
                    }
                });
            }
        };
    } catch (JSONException e) {
        Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
    }
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            try {
                String playStateString = ((JSONObject) response).getString("playState");
                PlayStateStatus playState = parsePlayState(playStateString);
                Util.postSuccess(listener, playState);
            } catch (JSONException e) {
                this.onError(new ServiceCommandError(0, "JSON Parse error", null));
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    });
    mActiveCommands.put(requestId, command);
    sendMessage(message, new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    });
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) JSONObject(org.json.JSONObject) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 82 with ServiceCommandError

use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.

the class RokuService method getAppList.

@Override
public void getAppList(final AppListListener listener) {
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            String msg = (String) response;
            SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
            InputStream stream;
            try {
                stream = new ByteArrayInputStream(msg.getBytes("UTF-8"));
                SAXParser saxParser = saxParserFactory.newSAXParser();
                RokuApplicationListParser parser = new RokuApplicationListParser();
                saxParser.parse(stream, parser);
                List<AppInfo> appList = parser.getApplicationList();
                Util.postSuccess(listener, appList);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    String action = "query";
    String param = "apps";
    String uri = requestURL(action, param);
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, null, responseListener);
    request.setHttpMethod(ServiceCommand.TYPE_GET);
    request.send();
}
Also used : RokuApplicationListParser(com.connectsdk.service.roku.RokuApplicationListParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) IOException(java.io.IOException) AppInfo(com.connectsdk.core.AppInfo) SAXException(org.xml.sax.SAXException) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) JSONObject(org.json.JSONObject) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ServiceCommand(com.connectsdk.service.command.ServiceCommand) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 83 with ServiceCommandError

use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.

the class DIALService method launchYouTube.

@Override
public void launchYouTube(String contentId, float startTime, AppLaunchListener listener) {
    String params = null;
    AppInfo appInfo = new AppInfo("YouTube");
    appInfo.setName(appInfo.getId());
    if (contentId != null && contentId.length() > 0) {
        if (startTime < 0.0) {
            if (listener != null) {
                listener.onError(new ServiceCommandError(0, "Start time may not be negative", null));
            }
            return;
        }
        String pairingCode = java.util.UUID.randomUUID().toString();
        params = String.format(Locale.US, "pairingCode=%s&v=%s&t=%.1f", pairingCode, contentId, startTime);
    }
    launchAppWithInfo(appInfo, params, listener);
}
Also used : ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) AppInfo(com.connectsdk.core.AppInfo)

Example 84 with ServiceCommandError

use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.

the class DIALService method launchApp.

private void launchApp(String appId, JSONObject params, AppLaunchListener listener) {
    if (appId == null || appId.length() == 0) {
        Util.postError(listener, new ServiceCommandError(0, "Must pass a valid appId", null));
        return;
    }
    AppInfo appInfo = new AppInfo();
    appInfo.setName(appId);
    appInfo.setId(appId);
    launchAppWithInfo(appInfo, listener);
}
Also used : ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) AppInfo(com.connectsdk.core.AppInfo)

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