Search in sources :

Example 1 with VideoCastConsumer

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

the class VideoCastManager method onRemoteMediaPreloadStatusUpdated.

private void onRemoteMediaPreloadStatusUpdated() {
    MediaQueueItem item = null;
    mMediaStatus = mRemoteMediaPlayer != null ? mRemoteMediaPlayer.getMediaStatus() : null;
    if (mMediaStatus != null) {
        item = mMediaStatus.getQueueItemById(mMediaStatus.getPreloadedItemId());
    }
    mPreLoadingItem = item;
    updateMiniControllersVisibilityForUpcoming(item);
    LOGD(TAG, "onRemoteMediaPreloadStatusUpdated() " + item);
    for (VideoCastConsumer consumer : mVideoConsumers) {
        consumer.onRemoteMediaPreloadStatusUpdated(item);
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer) MediaQueueItem(com.google.android.gms.cast.MediaQueueItem)

Example 2 with VideoCastConsumer

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

the class VideoCastManager method onApplicationConnectionFailed.

@Override
public void onApplicationConnectionFailed(int errorCode) {
    LOGD(TAG, "onApplicationConnectionFailed() reached with errorCode: " + errorCode);
    mApplicationErrorCode = 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 (VideoCastConsumer consumer : mVideoConsumers) {
            consumer.onApplicationConnectionFailed(errorCode);
        }
        onDeviceSelected(null, /* CastDevice */
        null);
        if (mMediaRouter != null) {
            LOGD(TAG, "onApplicationConnectionFailed(): Setting route to default");
            mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
        }
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer)

Example 3 with VideoCastConsumer

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

the class VideoCastManager method onQueueUpdated.

/*
    * This is called by onQueueStatusUpdated() of RemoteMediaPlayer
    */
private void onQueueUpdated(List<MediaQueueItem> queueItems, MediaQueueItem item, int repeatMode, boolean shuffle) {
    LOGD(TAG, "onQueueUpdated() reached");
    LOGD(TAG, String.format("Queue Items size: %d, Item: %s, Repeat Mode: %d, Shuffle: %s", queueItems == null ? 0 : queueItems.size(), item, repeatMode, shuffle));
    if (queueItems != null) {
        mMediaQueue = new MediaQueue(new CopyOnWriteArrayList<>(queueItems), item, shuffle, repeatMode);
    } else {
        mMediaQueue = new MediaQueue(new CopyOnWriteArrayList<MediaQueueItem>(), null, false, MediaStatus.REPEAT_MODE_REPEAT_OFF);
    }
    for (VideoCastConsumer consumer : mVideoConsumers) {
        consumer.onMediaQueueUpdated(queueItems, item, repeatMode, shuffle);
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 4 with VideoCastConsumer

use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer 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 5 with VideoCastConsumer

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

the class VideoCastManager method onRemoteMediaPlayerMetadataUpdated.

/*
     * This is called by onMetadataUpdated() of RemoteMediaPlayer
     */
public void onRemoteMediaPlayerMetadataUpdated() {
    LOGD(TAG, "onRemoteMediaPlayerMetadataUpdated() reached");
    updateMediaSessionMetadata();
    for (VideoCastConsumer consumer : mVideoConsumers) {
        consumer.onRemoteMediaPlayerMetadataUpdated();
    }
    try {
        updateLockScreenImage(getRemoteMediaInformation());
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "Failed to update lock screen metadata due to a network issue", e);
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)

Aggregations

VideoCastConsumer (com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer)11 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)5 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)5 MediaQueueItem (com.google.android.gms.cast.MediaQueueItem)2 MediaChannelResult (com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult)2 IOException (java.io.IOException)2 SuppressLint (android.annotation.SuppressLint)1 NotFoundException (android.content.res.Resources.NotFoundException)1 Point (android.graphics.Point)1 RouteInfo (android.support.v7.media.MediaRouter.RouteInfo)1 MessageReceivedCallback (com.google.android.gms.cast.Cast.MessageReceivedCallback)1 CastDevice (com.google.android.gms.cast.CastDevice)1 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1