Search in sources :

Example 1 with MediaChannelResult

use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult in project Shuttle by timusus.

the class VideoCastManager method onApplicationConnected.

@Override
protected void onApplicationConnected(ApplicationMetadata appMetadata, String applicationStatus, String sessionId, boolean wasLaunched) {
    LOGD(TAG, "onApplicationConnected() reached with sessionId: " + sessionId + ", and mReconnectionStatus=" + mReconnectionStatus);
    mApplicationErrorCode = NO_APPLICATION_ERROR;
    if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
        // we have tried to reconnect and successfully launched the app, so
        // it is time to select the route and make the cast icon happy :-)
        List<RouteInfo> routes = mMediaRouter.getRoutes();
        if (routes != null) {
            String routeId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_ROUTE_ID);
            for (RouteInfo routeInfo : routes) {
                if (routeId.equals(routeInfo.getId())) {
                    // found the right route
                    LOGD(TAG, "Found the correct route during reconnection attempt");
                    mReconnectionStatus = RECONNECTION_STATUS_FINALIZED;
                    mMediaRouter.selectRoute(routeInfo);
                    break;
                }
            }
        }
    }
    startNotificationService();
    try {
        attachDataChannel();
        attachMediaChannel();
        mSessionId = sessionId;
        // saving device for future retrieval; we only save the last session info
        mPreferenceAccessor.saveStringToPreference(PREFS_KEY_SESSION_ID, mSessionId);
        mRemoteMediaPlayer.requestStatus(mApiClient).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

            @Override
            public void onResult(MediaChannelResult result) {
                if (!result.getStatus().isSuccess()) {
                    onFailed(R.string.ccl_failed_status_request, result.getStatus().getStatusCode());
                }
            }
        });
        for (VideoCastConsumer consumer : mVideoConsumers) {
            consumer.onApplicationConnected(appMetadata, mSessionId, wasLaunched);
        }
    } catch (TransientNetworkDisconnectionException e) {
        LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
        onFailed(R.string.ccl_failed_no_connection_trans, NO_STATUS_CODE);
    } catch (NoConnectionException e) {
        LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
        onFailed(R.string.ccl_failed_no_connection, NO_STATUS_CODE);
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) RouteInfo(android.support.v7.media.MediaRouter.RouteInfo)

Example 2 with MediaChannelResult

use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult in project zype-android by zype.

the class VideoCastManager method onTextTrackStyleChanged.

/**
 * Signals a change in the Text Track style. Clients should not call this directly.
 */
public void onTextTrackStyleChanged(TextTrackStyle style) {
    LOGD(TAG, "onTextTrackStyleChanged() reached");
    if (mRemoteMediaPlayer == null || mRemoteMediaPlayer.getMediaInfo() == null) {
        return;
    }
    mRemoteMediaPlayer.setTextTrackStyle(mApiClient, style).setResultCallback(new ResultCallback<MediaChannelResult>() {

        @Override
        public void onResult(MediaChannelResult result) {
            if (!result.getStatus().isSuccess()) {
                onFailed(R.string.ccl_failed_to_set_track_style, result.getStatus().getStatusCode());
            }
        }
    });
    for (VideoCastConsumer consumer : mVideoConsumers) {
        try {
            consumer.onTextTrackStyleChanged(style);
        } catch (Exception e) {
            LOGE(TAG, "onTextTrackStyleChanged(): Failed to inform " + consumer, e);
        }
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) NotFoundException(android.content.res.Resources.NotFoundException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) IOException(java.io.IOException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Example 3 with MediaChannelResult

use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult in project Shuttle by timusus.

the class VideoCastManager method onTextTrackStyleChanged.

/**
 * Signals a change in the Text Track style. Clients should not call this directly.
 */
public void onTextTrackStyleChanged(TextTrackStyle style) {
    LOGD(TAG, "onTextTrackStyleChanged() reached");
    if (mRemoteMediaPlayer == null || mRemoteMediaPlayer.getMediaInfo() == null) {
        return;
    }
    mRemoteMediaPlayer.setTextTrackStyle(mApiClient, style).setResultCallback(new ResultCallback<MediaChannelResult>() {

        @Override
        public void onResult(MediaChannelResult result) {
            if (!result.getStatus().isSuccess()) {
                onFailed(R.string.ccl_failed_to_set_track_style, result.getStatus().getStatusCode());
            }
        }
    });
    for (VideoCastConsumer consumer : mVideoConsumers) {
        try {
            consumer.onTextTrackStyleChanged(style);
        } catch (Exception e) {
            LOGE(TAG, "onTextTrackStyleChanged(): Failed to inform " + consumer, e);
        }
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) NotFoundException(android.content.res.Resources.NotFoundException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) IOException(java.io.IOException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Example 4 with MediaChannelResult

use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult 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 5 with MediaChannelResult

use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult 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)

Aggregations

MediaChannelResult (com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult)6 VideoCastConsumer (com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer)4 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)4 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)4 IOException (java.io.IOException)4 NotFoundException (android.content.res.Resources.NotFoundException)2 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)2 Status (com.google.android.gms.common.api.Status)2 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)2 RouteInfo (android.support.v7.media.MediaRouter.RouteInfo)1 RouteInfo (androidx.mediarouter.media.MediaRouter.RouteInfo)1 CastWebAppSession (com.connectsdk.service.sessions.CastWebAppSession)1 WebAppSession (com.connectsdk.service.sessions.WebAppSession)1 LaunchOptions (com.google.android.gms.cast.LaunchOptions)1 RemoteMediaPlayer (com.google.android.gms.cast.RemoteMediaPlayer)1 TextTrackStyle (com.google.android.gms.cast.TextTrackStyle)1 ResultCallback (com.google.android.gms.common.api.ResultCallback)1