Search in sources :

Example 1 with CastDevice

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

the class BaseCastManager method reconnectSessionIfPossibleInternal.

private void reconnectSessionIfPossibleInternal(RouteInfo theRoute) {
    if (isConnected()) {
        return;
    }
    String sessionId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_SESSION_ID);
    String routeId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_ROUTE_ID);
    LOGD(TAG, "reconnectSessionIfPossible() Retrieved from preferences: " + "sessionId=" + sessionId + ", routeId=" + routeId);
    if (sessionId == null || routeId == null) {
        return;
    }
    setReconnectionStatus(RECONNECTION_STATUS_IN_PROGRESS);
    CastDevice device = CastDevice.getFromBundle(theRoute.getExtras());
    if (device != null) {
        LOGD(TAG, "trying to acquire Cast Client for " + device);
        onDeviceSelected(device, theRoute);
    }
}
Also used : CastDevice(com.google.android.gms.cast.CastDevice)

Example 2 with CastDevice

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

the class CastMediaRouterCallback method onRouteSelected.

@Override
public void onRouteSelected(MediaRouter router, RouteInfo info) {
    LOGD(TAG, "onRouteSelected: info=" + info);
    if (mCastManager.getReconnectionStatus() == BaseCastManager.RECONNECTION_STATUS_FINALIZED) {
        mCastManager.setReconnectionStatus(BaseCastManager.RECONNECTION_STATUS_INACTIVE);
        mCastManager.cancelReconnectionTask();
        return;
    }
    mCastManager.getPreferenceAccessor().saveStringToPreference(BaseCastManager.PREFS_KEY_ROUTE_ID, info.getId());
    CastDevice device = CastDevice.getFromBundle(info.getExtras());
    mCastManager.onDeviceSelected(device, info);
    LOGD(TAG, "onRouteSelected: mSelectedDevice=" + (device != null ? device.getFriendlyName() : "Null"));
}
Also used : CastDevice(com.google.android.gms.cast.CastDevice)

Example 3 with CastDevice

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

the class VideoCastManager method attachDataChannel.

/*
     * If a data namespace was provided when initializing this class, we set things up for a data
     * channel
     *
     * @throws NoConnectionException
     * @throws TransientNetworkDisconnectionException
     */
private void attachDataChannel() throws TransientNetworkDisconnectionException, NoConnectionException {
    if (TextUtils.isEmpty(mDataNamespace)) {
        return;
    }
    if (mDataChannel != null) {
        return;
    }
    checkConnectivity();
    mDataChannel = new MessageReceivedCallback() {

        @Override
        public void onMessageReceived(CastDevice castDevice, String namespace, String message) {
            for (VideoCastConsumer consumer : mVideoConsumers) {
                consumer.onDataMessageReceived(message);
            }
        }
    };
    try {
        Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mDataNamespace, mDataChannel);
    } catch (IOException | IllegalStateException e) {
        LOGE(TAG, "attachDataChannel()", e);
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer) CastDevice(com.google.android.gms.cast.CastDevice) IOException(java.io.IOException) MessageReceivedCallback(com.google.android.gms.cast.Cast.MessageReceivedCallback)

Example 4 with CastDevice

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

the class CastMediaRouterCallback method onRouteAdded.

@Override
public void onRouteAdded(MediaRouter router, RouteInfo routeInfo) {
    if (!router.getDefaultRoute().equals(routeInfo)) {
        notifyRouteAvailabilityChangedIfNeeded(router);
        mCastManager.onCastDeviceDetected(routeInfo);
    }
    if (mCastManager.getReconnectionStatus() == BaseCastManager.RECONNECTION_STATUS_STARTED) {
        String routeId = mCastManager.getPreferenceAccessor().getStringFromPreference(BaseCastManager.PREFS_KEY_ROUTE_ID);
        if (routeInfo.getId().equals(routeId)) {
            // we found the route, so lets go with that
            LOGD(TAG, "onRouteAdded: Attempting to recover a session with info=" + routeInfo);
            mCastManager.setReconnectionStatus(BaseCastManager.RECONNECTION_STATUS_IN_PROGRESS);
            CastDevice device = CastDevice.getFromBundle(routeInfo.getExtras());
            LOGD(TAG, "onRouteAdded: Attempting to recover a session with device: " + (device != null ? device.getFriendlyName() : "Null"));
            mCastManager.onDeviceSelected(device, routeInfo);
        }
    }
}
Also used : CastDevice(com.google.android.gms.cast.CastDevice)

Aggregations

CastDevice (com.google.android.gms.cast.CastDevice)4 MessageReceivedCallback (com.google.android.gms.cast.Cast.MessageReceivedCallback)1 VideoCastConsumer (com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer)1 IOException (java.io.IOException)1