Search in sources :

Example 1 with Service

use of com.connectsdk.discovery.provider.ssdp.Service in project butter-android by butterproject.

the class DLNAService method resubscribeServices.

public void resubscribeServices() {
    resubscriptionTimer = new Timer();
    resubscriptionTimer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            Util.runInBackground(new Runnable() {

                @Override
                public void run() {
                    List<Service> serviceList = serviceDescription.getServiceList();
                    if (serviceList != null) {
                        for (int i = 0; i < serviceList.size(); i++) {
                            String eventSubURL = makeControlURL("/", serviceList.get(i).eventSubURL);
                            if (eventSubURL == null) {
                                continue;
                            }
                            String SID = SIDList.get(serviceList.get(i).serviceType);
                            try {
                                HttpConnection connection = HttpConnection.newSubscriptionInstance(new URI("http", "", serviceDescription.getIpAddress(), serviceDescription.getPort(), eventSubURL, "", ""));
                                connection.setMethod(HttpConnection.Method.SUBSCRIBE);
                                connection.setHeader("TIMEOUT", "Second-" + TIMEOUT);
                                connection.setHeader("SID", SID);
                                connection.execute();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            });
        }
    }, TIMEOUT / 2 * 1000, TIMEOUT / 2 * 1000);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) HttpConnection(com.connectsdk.etc.helper.HttpConnection) Service(com.connectsdk.discovery.provider.ssdp.Service) URI(java.net.URI) 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)

Aggregations

Service (com.connectsdk.discovery.provider.ssdp.Service)1 HttpConnection (com.connectsdk.etc.helper.HttpConnection)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 ParseException (java.text.ParseException)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 TransformerException (javax.xml.transform.TransformerException)1 JSONException (org.json.JSONException)1