Search in sources :

Example 1 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.

the class AirPlayService method playVideo.

public void playVideo(final String url, String mimeType, String title, String description, String iconSrc, boolean shouldLoop, final LaunchListener listener) {
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

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

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    String uri = getRequestURL("play");
    String payload = null;
    PListBuilder builder = new PListBuilder();
    builder.putString("Content-Location", url);
    builder.putReal("Start-Position", 0);
    payload = builder.toString();
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, responseListener);
    request.send();
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession) PListBuilder(com.connectsdk.service.airplay.PListBuilder) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 2 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession 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 3 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.

the class WebOSTVService method launchInputPicker.

@Override
public void launchInputPicker(final AppLaunchListener listener) {
    final AppInfo appInfo = new AppInfo() {

        {
            setId("com.webos.app.inputpicker");
            setName("InputPicker");
        }
    };
    launchAppWithInfo(appInfo, null, new AppLaunchListener() {

        @Override
        public void onSuccess(LaunchSession object) {
            listener.onSuccess(object);
        }

        @Override
        public void onError(ServiceCommandError error) {
            appInfo.setId("com.webos.app.inputmgr");
            launchAppWithInfo(appInfo, null, listener);
        }
    });
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) AppInfo(com.connectsdk.core.AppInfo)

Example 4 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.

the class WebOSTVService method joinWebApp.

@Override
public void joinWebApp(String webAppId, WebAppSession.LaunchListener listener) {
    LaunchSession launchSession = LaunchSession.launchSessionForAppId(webAppId);
    launchSession.setSessionType(LaunchSessionType.WebApp);
    launchSession.setService(this);
    joinWebApp(launchSession, listener);
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession)

Example 5 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession 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)

Aggregations

LaunchSession (com.connectsdk.service.sessions.LaunchSession)17 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)12 JSONObject (org.json.JSONObject)10 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)9 ServiceCommand (com.connectsdk.service.command.ServiceCommand)9 JSONException (org.json.JSONException)6 HashMap (java.util.HashMap)4 AppInfo (com.connectsdk.core.AppInfo)2 WebOSWebAppSession (com.connectsdk.service.sessions.WebOSWebAppSession)2 IOException (java.io.IOException)2 PListBuilder (com.connectsdk.service.airplay.PListBuilder)1 CastWebAppSession (com.connectsdk.service.sessions.CastWebAppSession)1 WebAppSession (com.connectsdk.service.sessions.WebAppSession)1 ApplicationMetadata (com.google.android.gms.cast.ApplicationMetadata)1 ApplicationConnectionResult (com.google.android.gms.cast.Cast.ApplicationConnectionResult)1 LaunchOptions (com.google.android.gms.cast.LaunchOptions)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1