Search in sources :

Example 66 with ServiceCommandError

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

the class WebOSTVService method connectToApp.

/* Connect to a native/installed webOS app */
public void connectToApp(String appId, final WebAppSession.LaunchListener listener) {
    LaunchSession launchSession = LaunchSession.launchSessionForAppId(appId);
    launchSession.setSessionType(LaunchSessionType.App);
    launchSession.setService(this);
    final WebOSWebAppSession webAppSession = webAppSessionForLaunchSession(launchSession);
    connectToWebApp(webAppSession, false, new ResponseListener<Object>() {

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

        @Override
        public void onSuccess(Object object) {
            Util.postSuccess(listener, webAppSession);
        }
    });
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession)

Example 67 with ServiceCommandError

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

the class CastService method getPlayState.

@Override
public void getPlayState(PlayStateListener listener) {
    if (mMediaPlayer != null && mMediaPlayer.getMediaStatus() != null) {
        PlayStateStatus status = PlayStateStatus.convertPlayerStateToPlayStateStatus(mMediaPlayer.getMediaStatus().getPlayerState());
        Util.postSuccess(listener, status);
    } else {
        Util.postError(listener, new ServiceCommandError(0, "There is no media currently available", null));
    }
}
Also used : ServiceCommandError(com.connectsdk.service.command.ServiceCommandError)

Example 68 with ServiceCommandError

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

the class CastService method playMedia.

private void playMedia(final com.google.android.gms.cast.MediaInfo mediaInformation, final String mediaAppId, final LaunchListener listener) {
    final ApplicationConnectionResultCallback webAppLaunchCallback = new ApplicationConnectionResultCallback(new LaunchWebAppListener() {

        @Override
        public void onSuccess(final WebAppSession webAppSession) {
            ConnectionListener connectionListener = new ConnectionListener() {

                @Override
                public void onConnected() {
                    try {
                        mMediaPlayer.load(mApiClient, mediaInformation, true).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

                            @Override
                            public void onResult(MediaChannelResult result) {
                                Status status = result.getStatus();
                                if (status.isSuccess()) {
                                    webAppSession.launchSession.setSessionType(LaunchSessionType.Media);
                                    // White text, black outline, no background
                                    TextTrackStyle textTrackStyle = new TextTrackStyle();
                                    textTrackStyle.setForegroundColor(Color.parseColor("#FFFFFFFF"));
                                    textTrackStyle.setBackgroundColor(Color.parseColor("#01000000"));
                                    textTrackStyle.setWindowType(TextTrackStyle.WINDOW_TYPE_NONE);
                                    textTrackStyle.setEdgeType(TextTrackStyle.EDGE_TYPE_OUTLINE);
                                    textTrackStyle.setEdgeColor(Color.BLACK);
                                    textTrackStyle.setFontGenericFamily(TextTrackStyle.FONT_FAMILY_SANS_SERIF);
                                    mMediaPlayer.setTextTrackStyle(mApiClient, textTrackStyle);
                                    mMediaPlayer.setActiveMediaTracks(mApiClient, new long[] { 1 });
                                    Util.postSuccess(listener, new MediaLaunchObject(webAppSession.launchSession, CastService.this));
                                } else {
                                    Util.postError(listener, new ServiceCommandError(status.getStatusCode(), status.getStatusMessage(), status));
                                }
                            }
                        });
                    } catch (Exception e) {
                        Util.postError(listener, new ServiceCommandError(0, "Unable to load", null));
                    }
                }
            };
            runCommand(connectionListener);
        }

        @Override
        public void onFailure(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    });
    launchingAppId = mediaAppId;
    ConnectionListener connectionListener = new ConnectionListener() {

        @Override
        public void onConnected() {
            boolean relaunchIfRunning = false;
            try {
                if (Cast.CastApi.getApplicationStatus(mApiClient) == null || (!mediaAppId.equals(currentAppId))) {
                    relaunchIfRunning = true;
                }
                LaunchOptions options = new LaunchOptions();
                options.setRelaunchIfRunning(relaunchIfRunning);
                Cast.CastApi.launchApplication(mApiClient, mediaAppId, options).setResultCallback(webAppLaunchCallback);
            } catch (Exception e) {
                Util.postError(listener, new ServiceCommandError(0, "Unable to launch", null));
            }
        }
    };
    runCommand(connectionListener);
}
Also used : Status(com.google.android.gms.common.api.Status) ResultCallback(com.google.android.gms.common.api.ResultCallback) RemoteMediaPlayer(com.google.android.gms.cast.RemoteMediaPlayer) WebAppSession(com.connectsdk.service.sessions.WebAppSession) CastWebAppSession(com.connectsdk.service.sessions.CastWebAppSession) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) IOException(java.io.IOException) LaunchOptions(com.google.android.gms.cast.LaunchOptions) TextTrackStyle(com.google.android.gms.cast.TextTrackStyle) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult)

Example 69 with ServiceCommandError

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

the class CastService method seek.

@Override
public void seek(final long position, final ResponseListener<Object> listener) {
    if (mMediaPlayer == null || mMediaPlayer.getMediaStatus() == null) {
        Util.postError(listener, new ServiceCommandError(0, "There is no media currently available", null));
        return;
    }
    ConnectionListener connectionListener = new ConnectionListener() {

        @Override
        public void onConnected() {
            try {
                mMediaPlayer.seek(mApiClient, position, RemoteMediaPlayer.RESUME_STATE_UNCHANGED).setResultCallback(new ResultCallback<MediaChannelResult>() {

                    @Override
                    public void onResult(MediaChannelResult result) {
                        Status status = result.getStatus();
                        if (status.isSuccess()) {
                            Util.postSuccess(listener, null);
                        } else {
                            Util.postError(listener, new ServiceCommandError(status.getStatusCode(), status.getStatusMessage(), status));
                        }
                    }
                });
            } catch (Exception e) {
                Util.postError(listener, new ServiceCommandError(0, "Unable to seek", null));
            }
        }
    };
    runCommand(connectionListener);
}
Also used : Status(com.google.android.gms.common.api.Status) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult) IOException(java.io.IOException)

Example 70 with ServiceCommandError

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

the class WebOSTVService method joinWebApp.

@Override
public void joinWebApp(final LaunchSession webAppLaunchSession, final WebAppSession.LaunchListener listener) {
    final WebOSWebAppSession webAppSession = this.webAppSessionForLaunchSession(webAppLaunchSession);
    webAppSession.join(new ResponseListener<Object>() {

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

        @Override
        public void onSuccess(Object object) {
            Util.postSuccess(listener, webAppSession);
        }
    });
}
Also used : JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession)

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