Search in sources :

Example 6 with ServiceCommandError

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

the class DLNAService method getMediaInfo.

@Override
public void getMediaInfo(final MediaInfoListener listener) {
    getPositionInfo(new PositionInfoListener() {

        @Override
        public void onGetPositionInfoSuccess(final String positionInfoXml) {
            Util.runInBackground(new Runnable() {

                @Override
                public void run() {
                    String baseUrl = "http://" + getServiceDescription().getIpAddress() + ":" + getServiceDescription().getPort();
                    String trackMetaData = parseData(positionInfoXml, "TrackMetaData");
                    MediaInfo info = DLNAMediaInfoParser.getMediaInfo(trackMetaData, baseUrl);
                    Util.postSuccess(listener, info);
                }
            });
        }

        @Override
        public void onGetPositionInfoFailed(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    });
}
Also used : MediaInfo(com.connectsdk.core.MediaInfo) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError)

Example 7 with ServiceCommandError

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

the class DLNAService method displayMedia.

public void displayMedia(String url, String subsUrl, String mimeType, String title, String description, String iconSrc, final LaunchListener listener) {
    final String instanceId = "0";
    String[] mediaElements = mimeType.split("/");
    String mediaType = mediaElements[0];
    String mediaFormat = mediaElements[1];
    if (mediaType == null || mediaType.length() == 0 || mediaFormat == null || mediaFormat.length() == 0) {
        Util.postError(listener, new ServiceCommandError(0, "You must provide a valid mimeType (audio/*,  video/*, etc)", null));
        return;
    }
    mediaFormat = "mp3".equals(mediaFormat) ? "mpeg" : mediaFormat;
    String mMimeType = String.format("%s/%s", mediaType, mediaFormat);
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            String method = "Play";
            Map<String, String> parameters = new HashMap<String, String>();
            parameters.put("Speed", "1");
            String payload = getMessageXml(AV_TRANSPORT_URN, method, "0", parameters);
            ResponseListener<Object> playResponseListener = new ResponseListener<Object>() {

                @Override
                public void onSuccess(Object response) {
                    LaunchSession launchSession = new LaunchSession();
                    launchSession.setService(DLNAService.this);
                    launchSession.setSessionType(LaunchSessionType.Media);
                    Util.postSuccess(listener, new MediaLaunchObject(launchSession, DLNAService.this, DLNAService.this));
                }

                @Override
                public void onError(ServiceCommandError error) {
                    Util.postError(listener, error);
                }
            };
            ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(DLNAService.this, method, payload, playResponseListener);
            request.send();
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    String method = "SetAVTransportURI";
    String metadata = getMetadata(url, subsUrl, mMimeType, title, description, iconSrc);
    if (metadata == null) {
        Util.postError(listener, ServiceCommandError.getError(500));
        return;
    }
    Map<String, String> params = new LinkedHashMap<String, String>();
    try {
        params.put("CurrentURI", encodeURL(url));
    } catch (Exception e) {
        Util.postError(listener, ServiceCommandError.getError(500));
        return;
    }
    params.put("CurrentURIMetaData", metadata);
    String payload = getMessageXml(AV_TRANSPORT_URN, method, instanceId, params);
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(DLNAService.this, method, payload, responseListener);
    request.send();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LaunchSession(com.connectsdk.service.sessions.LaunchSession) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TransformerException(javax.xml.transform.TransformerException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.JSONObject) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 8 with ServiceCommandError

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

the class NetcastTVService method connectMouse.

@Override
public void connectMouse() {
    ResponseListener<Object> listener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            Log.d(Util.T, "Netcast TV's mouse has been connected");
            mMouseDistance = new PointF(0, 0);
            mMouseIsMoving = false;
        }

        @Override
        public void onError(ServiceCommandError error) {
            Log.w(Util.T, "Netcast TV's mouse connection has been failed");
        }
    };
    setMouseCursorVisible(true, listener);
}
Also used : PointF(android.graphics.PointF) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener)

Example 9 with ServiceCommandError

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

the class NetcastTVService method getApplications.

private void getApplications(int type, int number, final AppListListener listener) {
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            String strObj = (String) response;
            JSONArray applicationArray = parseApplicationsXmlToJSON(strObj);
            List<AppInfo> appList = new ArrayList<AppInfo>();
            for (int i = 0; i < applicationArray.length(); i++) {
                try {
                    final JSONObject appJSON = applicationArray.getJSONObject(i);
                    AppInfo appInfo = new AppInfo() {

                        {
                            setId(appJSON.getString("id"));
                            setName(appJSON.getString("title"));
                        }
                    };
                    appList.add(appInfo);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            Util.postSuccess(listener, appList);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_APPLIST_GET, String.valueOf(type), "0", String.valueOf(number));
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
    command.setHttpMethod(ServiceCommand.TYPE_GET);
    command.send();
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) 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) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 10 with ServiceCommandError

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

the class NetcastTVService method getChannelList.

@Override
public void getChannelList(final ChannelListListener listener) {
    String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_CHANNEL_LIST);
    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();
                ArrayList<ChannelInfo> channelList = new ArrayList<ChannelInfo>();
                for (int i = 0; i < channelArray.length(); i++) {
                    JSONObject rawData;
                    try {
                        rawData = (JSONObject) channelArray.get(i);
                        ChannelInfo channel = NetcastChannelParser.parseRawChannelData(rawData);
                        channelList.add(channel);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                Util.postSuccess(listener, channelList);
            } 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);
        }
    };
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
    request.setHttpMethod(ServiceCommand.TYPE_GET);
    request.send();
}
Also used : NetcastChannelParser(com.connectsdk.service.netcast.NetcastChannelParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) 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)

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