Search in sources :

Example 1 with DataCastConsumer

use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.DataCastConsumer in project Shuttle by timusus.

the class DataCastManager method onApplicationConnected.

@Override
public void onApplicationConnected(ApplicationMetadata appMetadata, String applicationStatus, String sessionId, boolean wasLaunched) {
    LOGD(TAG, "onApplicationConnected() reached with sessionId: " + sessionId);
    // saving session for future retrieval; we only save the last session info
    mPreferenceAccessor.saveStringToPreference(PREFS_KEY_SESSION_ID, sessionId);
    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);
            boolean found = false;
            for (RouteInfo routeInfo : routes) {
                if (routeId.equals(routeInfo.getId())) {
                    // found the right route
                    LOGD(TAG, "Found the correct route during reconnection attempt");
                    found = true;
                    mReconnectionStatus = RECONNECTION_STATUS_FINALIZED;
                    mMediaRouter.selectRoute(routeInfo);
                    break;
                }
            }
            if (!found) {
                // we were hoping to have the route that we wanted, but we
                // didn't so we deselect the device
                onDeviceSelected(null, /* CastDevice */
                null);
                mReconnectionStatus = RECONNECTION_STATUS_INACTIVE;
                return;
            }
        }
    }
    // registering namespaces, if any
    try {
        attachDataChannels();
        mSessionId = sessionId;
        for (DataCastConsumer consumer : mDataConsumers) {
            consumer.onApplicationConnected(appMetadata, applicationStatus, sessionId, wasLaunched);
        }
    } catch (IllegalStateException | IOException e) {
        LOGE(TAG, "Failed to attach namespaces", e);
    }
}
Also used : IOException(java.io.IOException) RouteInfo(android.support.v7.media.MediaRouter.RouteInfo) DataCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.DataCastConsumer)

Example 2 with DataCastConsumer

use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.DataCastConsumer in project Shuttle by timusus.

the class DataCastManager method onApplicationConnectionFailed.

@Override
public void onApplicationConnectionFailed(int errorCode) {
    if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
        if (errorCode == CastStatusCodes.APPLICATION_NOT_RUNNING) {
            // while trying to re-establish session, we found out that the app is not running
            // so we need to disconnect
            mReconnectionStatus = RECONNECTION_STATUS_INACTIVE;
            onDeviceSelected(null, /* CastDevice */
            null);
        }
    } else {
        for (DataCastConsumer consumer : mDataConsumers) {
            consumer.onApplicationConnectionFailed(errorCode);
        }
        onDeviceSelected(null, /* CastDevice */
        null);
        if (mMediaRouter != null) {
            LOGD(TAG, "onApplicationConnectionFailed(): Setting route to default");
            mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
        }
    }
}
Also used : DataCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.DataCastConsumer)

Example 3 with DataCastConsumer

use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.DataCastConsumer in project Shuttle by timusus.

the class DataCastManager method onApplicationStatusChanged.

public void onApplicationStatusChanged() {
    String appStatus;
    if (!isConnected()) {
        return;
    }
    try {
        appStatus = Cast.CastApi.getApplicationStatus(mApiClient);
        LOGD(TAG, "onApplicationStatusChanged() reached: " + appStatus);
        for (DataCastConsumer consumer : mDataConsumers) {
            consumer.onApplicationStatusChanged(appStatus);
        }
    } catch (IllegalStateException e) {
        LOGE(TAG, "onApplicationStatusChanged(): Failed", e);
    }
}
Also used : DataCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.DataCastConsumer)

Aggregations

DataCastConsumer (com.google.android.libraries.cast.companionlibrary.cast.callbacks.DataCastConsumer)3 RouteInfo (android.support.v7.media.MediaRouter.RouteInfo)1 IOException (java.io.IOException)1