Search in sources :

Example 36 with ServiceCommandError

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

the class WebOSWebAppSession method previous.

@Override
public void previous(final ResponseListener<Object> 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", "playPrevious");
                        put("requestId", requestId);
                    }
                });
            }
        };
    } catch (JSONException e) {
        Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
        return;
    }
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, listener);
    mActiveCommands.put(requestId, command);
    sendMessage(message, listener);
}
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 37 with ServiceCommandError

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

the class WebOSWebAppSession method jumpToTrack.

@Override
public void jumpToTrack(final long index, final ResponseListener<Object> 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", "jumpToTrack");
                        put("requestId", requestId);
                        put("index", (int) index);
                    }
                });
            }
        };
    } catch (JSONException e) {
        Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
        return;
    }
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, listener);
    mActiveCommands.put(requestId, command);
    sendMessage(message, listener);
}
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 38 with ServiceCommandError

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

the class WebOSWebAppSession method playMedia.

@Override
public void playMedia(final String url, final String mimeType, final String title, final String description, final String iconSrc, final boolean shouldLoop, final MediaPlayer.LaunchListener listener) {
    int requestIdNumber = getNextId();
    final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
    JSONObject message = null;
    try {
        message = new JSONObject() {

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

                    {
                        putOpt("type", "playMedia");
                        putOpt("mediaURL", url);
                        putOpt("iconURL", iconSrc);
                        putOpt("title", title);
                        putOpt("description", description);
                        putOpt("mimeType", mimeType);
                        putOpt("shouldLoop", shouldLoop);
                        putOpt("requestId", requestId);
                    }
                });
            }
        };
    } catch (JSONException e) {
        Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
        return;
    }
    ResponseListener<Object> response = new ResponseListener<Object>() {

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }

        @Override
        public void onSuccess(Object object) {
            Util.postSuccess(listener, new MediaLaunchObject(launchSession, getMediaControl(), getPlaylistControl()));
        }
    };
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, response);
    mActiveCommands.put(requestId, command);
    sendMessage(message, new ResponseListener<Object>() {

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }

        @Override
        public void onSuccess(Object object) {
        }
    });
}
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 39 with ServiceCommandError

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

the class WebOSWebAppSession method displayImage.

@Override
public void displayImage(final String url, final String mimeType, final String title, final String description, final String iconSrc, final MediaPlayer.LaunchListener listener) {
    int requestIdNumber = getNextId();
    final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
    JSONObject message = null;
    try {
        message = new JSONObject() {

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

                    {
                        putOpt("type", "displayImage");
                        putOpt("mediaURL", url);
                        putOpt("iconURL", iconSrc);
                        putOpt("title", title);
                        putOpt("description", description);
                        putOpt("mimeType", mimeType);
                        putOpt("requestId", requestId);
                    }
                });
            }
        };
    } catch (JSONException e) {
        Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
        return;
    }
    ResponseListener<Object> response = new ResponseListener<Object>() {

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }

        @Override
        public void onSuccess(Object object) {
            Util.postSuccess(listener, new MediaLaunchObject(launchSession, getMediaControl()));
        }
    };
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(socket, null, null, response);
    mActiveCommands.put(requestId, command);
    sendP2PMessage(message, new ResponseListener<Object>() {

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }

        @Override
        public void onSuccess(Object object) {
        }
    });
}
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 40 with ServiceCommandError

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

the class CastService method getMediaInfo.

@Override
public void getMediaInfo(MediaInfoListener listener) {
    if (mMediaPlayer == null)
        return;
    if (mMediaPlayer.getMediaInfo() != null) {
        String url = mMediaPlayer.getMediaInfo().getContentId();
        String mimeType = mMediaPlayer.getMediaInfo().getContentType();
        MediaMetadata metadata = mMediaPlayer.getMediaInfo().getMetadata();
        String title = null;
        String description = null;
        ArrayList<ImageInfo> list = null;
        if (metadata != null) {
            title = metadata.getString(MediaMetadata.KEY_TITLE);
            description = metadata.getString(MediaMetadata.KEY_SUBTITLE);
            if (metadata.getImages() != null && metadata.getImages().size() > 0) {
                String iconUrl = metadata.getImages().get(0).getUrl().toString();
                list = new ArrayList<ImageInfo>();
                list.add(new ImageInfo(iconUrl));
            }
        }
        MediaInfo info = new MediaInfo(url, mimeType, title, description, list);
        Util.postSuccess(listener, info);
    } else {
        Util.postError(listener, new ServiceCommandError(0, "Media Info is null", null));
    }
}
Also used : MediaInfo(com.connectsdk.core.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ImageInfo(com.connectsdk.core.ImageInfo)

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