Search in sources :

Example 46 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.

the class AirPlayService method getPlaybackPosition.

private void getPlaybackPosition(final PlaybackPositionListener listener) {
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            String strResponse = (String) response;
            long duration = 0;
            long position = 0;
            StringTokenizer st = new StringTokenizer(strResponse);
            while (st.hasMoreTokens()) {
                String str = st.nextToken();
                if (str.contains("duration")) {
                    duration = parseTimeValueFromString(st.nextToken());
                } else if (str.contains("position")) {
                    position = parseTimeValueFromString(st.nextToken());
                }
            }
            if (listener != null) {
                listener.onGetPlaybackPositionSuccess(duration, position);
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            if (listener != null)
                listener.onGetPlaybackPositionFailed(error);
        }
    };
    String uri = getRequestURL("scrub");
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, null, responseListener);
    request.setHttpMethod(ServiceCommand.TYPE_GET);
    request.send();
}
Also used : StringTokenizer(java.util.StringTokenizer) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 47 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.

the class NetcastTVService method getCurrentChannel.

@Override
public void getCurrentChannel(final ChannelListener listener) {
    String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_CURRENT_CHANNEL);
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            String strObj = (String) response;
            try {
                SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
                InputStream stream = new ByteArrayInputStream(strObj.getBytes("UTF-8"));
                SAXParser saxParser = saxParserFactory.newSAXParser();
                NetcastChannelParser parser = new NetcastChannelParser();
                saxParser.parse(stream, parser);
                JSONArray channelArray = parser.getJSONChannelArray();
                if (channelArray.length() > 0) {
                    JSONObject rawData = (JSONObject) channelArray.get(0);
                    ChannelInfo channel = NetcastChannelParser.parseRawChannelData(rawData);
                    Util.postSuccess(listener, channel);
                }
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
    request.send();
}
Also used : NetcastChannelParser(com.connectsdk.service.netcast.NetcastChannelParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ChannelInfo(com.connectsdk.core.ChannelInfo) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) JSONObject(org.json.JSONObject) 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 48 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.

the class NetcastTVService method launchApplication.

private void launchApplication(final String appName, final String auid, final String contentId, final Launcher.AppLaunchListener listener) {
    JSONObject jsonObj = new JSONObject();
    try {
        jsonObj.put("id", auid);
        jsonObj.put("title", appName);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            LaunchSession launchSession = LaunchSession.launchSessionForAppId(auid);
            launchSession.setAppName(appName);
            launchSession.setService(NetcastTVService.this);
            launchSession.setSessionType(LaunchSessionType.App);
            Util.postSuccess(listener, launchSession);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    String requestURL = getUDAPRequestURL(UDAP_PATH_APPTOAPP_COMMAND);
    Map<String, String> params = new HashMap<String, String>();
    params.put("name", "AppExecute");
    params.put("auid", auid);
    if (appName != null) {
        params.put("appname", appName);
    }
    if (contentId != null) {
        params.put("contentid", contentId);
    }
    String httpMessage = getUDAPMessageBody(UDAP_API_COMMAND, params);
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, httpMessage, responseListener);
    request.send();
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) 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 49 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.

the class NetcastTVService method getApplication.

public void getApplication(final String appName, final AppInfoListener listener) {
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            final String strObj = (String) response;
            AppInfo appId = new AppInfo() {

                {
                    setId(decToHex(strObj));
                }
            };
            Util.postSuccess(listener, appId);
        }

        @Override
        public void onError(ServiceCommandError error) {
            if (listener != null)
                Util.postError(listener, error);
        }
    };
    String uri = UDAP_PATH_APPTOAPP_DATA + appName;
    String requestURL = getUDAPRequestURL(uri);
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
    command.setHttpMethod(ServiceCommand.TYPE_GET);
    command.send();
}
Also used : JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand) AppInfo(com.connectsdk.core.AppInfo)

Example 50 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.

the class NetcastTVService method launchNetflix.

@Override
public void launchNetflix(final String contentId, final Launcher.AppLaunchListener listener) {
    if (!serviceDescription.getModelNumber().equals("4.0")) {
        launchApp("Netflix", listener);
        return;
    }
    final String appName = "Netflix";
    getApplication(appName, new AppInfoListener() {

        @Override
        public void onSuccess(final AppInfo appInfo) {
            JSONObject jsonObj = new JSONObject();
            try {
                jsonObj.put("id", appInfo.getId());
                jsonObj.put("name", appName);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            ResponseListener<Object> responseListener = new ResponseListener<Object>() {

                @Override
                public void onSuccess(Object response) {
                    LaunchSession launchSession = LaunchSession.launchSessionForAppId(appInfo.getId());
                    launchSession.setAppName(appName);
                    launchSession.setService(NetcastTVService.this);
                    launchSession.setSessionType(LaunchSessionType.App);
                    Util.postSuccess(listener, launchSession);
                }

                @Override
                public void onError(ServiceCommandError error) {
                    Util.postError(listener, error);
                }
            };
            String requestURL = getUDAPRequestURL(UDAP_PATH_APPTOAPP_COMMAND);
            Map<String, String> params = new HashMap<String, String>();
            params.put("name", "SearchCMDPlaySDPContent");
            params.put("content_type", "1");
            params.put("conts_exec_type", "20");
            params.put("conts_plex_type_flag", "N");
            params.put("conts_search_id", "2023237");
            params.put("conts_age", "18");
            params.put("exec_id", "netflix");
            params.put("item_id", "-Q m=http%3A%2F%2Fapi.netflix.com%2Fcatalog%2Ftitles%2Fmovies%2F" + contentId + "&amp;source_type=4&amp;trackId=6054700&amp;trackUrl=https%3A%2F%2Fapi.netflix.com%2FAPI_APP_ID_6261%3F%23Search%3F");
            params.put("app_type", "");
            String httpMessage = getUDAPMessageBody(UDAP_API_COMMAND, params);
            ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(NetcastTVService.this, requestURL, httpMessage, responseListener);
            request.send();
        }

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

Aggregations

ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)76 JSONObject (org.json.JSONObject)75 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)65 ServiceCommand (com.connectsdk.service.command.ServiceCommand)64 JSONException (org.json.JSONException)54 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)14 SuppressLint (android.annotation.SuppressLint)10 LaunchSession (com.connectsdk.service.sessions.LaunchSession)9 IOException (java.io.IOException)9 JSONArray (org.json.JSONArray)7 AppInfo (com.connectsdk.core.AppInfo)6 ChannelInfo (com.connectsdk.core.ChannelInfo)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 HttpConnection (com.connectsdk.etc.helper.HttpConnection)3 InputStream (java.io.InputStream)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3