Search in sources :

Example 6 with MediaChannelResult

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

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);
    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(androidx.mediarouter.media.MediaRouter.RouteInfo)

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