Search in sources :

Example 6 with VideoCastConsumer

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

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

the class VideoCastManager method onVolumeChanged.

private void onVolumeChanged() {
    LOGD(TAG, "onVolumeChanged() reached");
    double volume;
    try {
        volume = getVolume();
        boolean isMute = isMute();
        for (VideoCastConsumer consumer : mVideoConsumers) {
            consumer.onVolumeChanged(volume, isMute);
        }
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "Failed to get volume", 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)

Example 8 with VideoCastConsumer

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

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

the class VideoCastManager method onRemoteMediaPlayerStatusUpdated.

/*
     * This is called by onStatusUpdated() of the RemoteMediaPlayer
     */
private void onRemoteMediaPlayerStatusUpdated() {
    LOGD(TAG, "onRemoteMediaPlayerStatusUpdated() reached");
    if (mApiClient == null || mRemoteMediaPlayer == null || mRemoteMediaPlayer.getMediaStatus() == null) {
        LOGD(TAG, "mApiClient or mRemoteMediaPlayer is null, so will not proceed");
        return;
    }
    mMediaStatus = mRemoteMediaPlayer.getMediaStatus();
    List<MediaQueueItem> queueItems = mMediaStatus.getQueueItems();
    if (queueItems != null) {
        int itemId = mMediaStatus.getCurrentItemId();
        MediaQueueItem item = mMediaStatus.getQueueItemById(itemId);
        int repeatMode = mMediaStatus.getQueueRepeatMode();
        onQueueUpdated(queueItems, item, repeatMode, false);
    } else {
        onQueueUpdated(null, null, MediaStatus.REPEAT_MODE_REPEAT_OFF, false);
    }
    mState = mMediaStatus.getPlayerState();
    mIdleReason = mMediaStatus.getIdleReason();
    try {
        double volume = getVolume();
        boolean isMute = isMute();
        boolean makeUiHidden = false;
        if (mState == MediaStatus.PLAYER_STATE_PLAYING) {
            LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = playing");
            updateMediaSession(true);
            long mediaDurationLeft = getMediaTimeRemaining();
            startReconnectionService(mediaDurationLeft);
            startNotificationService();
        } else if (mState == MediaStatus.PLAYER_STATE_PAUSED) {
            LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = paused");
            updateMediaSession(false);
            startNotificationService();
        } else if (mState == MediaStatus.PLAYER_STATE_IDLE) {
            LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = IDLE with reason: " + mIdleReason);
            updateMediaSession(false);
            switch(mIdleReason) {
                case MediaStatus.IDLE_REASON_FINISHED:
                    if (mMediaStatus.getLoadingItemId() == MediaQueueItem.INVALID_ITEM_ID) {
                        // we have reached the end of queue
                        clearMediaSession();
                        makeUiHidden = true;
                    }
                    break;
                case MediaStatus.IDLE_REASON_ERROR:
                    // something bad happened on the cast device
                    LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): IDLE reason = ERROR");
                    makeUiHidden = true;
                    clearMediaSession();
                    onFailed(R.string.ccl_failed_receiver_player_error, NO_STATUS_CODE);
                    break;
                case MediaStatus.IDLE_REASON_CANCELED:
                    LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): IDLE reason = CANCELLED");
                    makeUiHidden = !isRemoteStreamLive();
                    break;
                case MediaStatus.IDLE_REASON_INTERRUPTED:
                    if (mMediaStatus.getLoadingItemId() == MediaQueueItem.INVALID_ITEM_ID) {
                        // we have reached the end of queue
                        clearMediaSession();
                        makeUiHidden = true;
                    }
                    break;
                default:
                    LOGE(TAG, "onRemoteMediaPlayerStatusUpdated(): Unexpected Idle Reason " + mIdleReason);
            }
        } else if (mState == MediaStatus.PLAYER_STATE_BUFFERING) {
            LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = buffering");
        } else {
            LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = unknown");
            makeUiHidden = true;
        }
        if (makeUiHidden) {
            stopReconnectionService();
            stopNotificationService();
        }
        updateMiniControllersVisibility(!makeUiHidden);
        updateMiniControllers();
        for (VideoCastConsumer consumer : mVideoConsumers) {
            consumer.onRemoteMediaPlayerStatusUpdated();
            consumer.onVolumeChanged(volume, isMute);
        }
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "Failed to get volume state due to network issues", 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) MediaQueueItem(com.google.android.gms.cast.MediaQueueItem) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 10 with VideoCastConsumer

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

the class VideoCastManager method onApplicationDisconnected.

private void onApplicationDisconnected(int errorCode) {
    LOGD(TAG, "onApplicationDisconnected() reached with error code: " + errorCode);
    mApplicationErrorCode = errorCode;
    updateMediaSession(false);
    if (mMediaSessionCompat != null && isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
        mMediaRouter.setMediaSessionCompat(null);
    }
    for (VideoCastConsumer consumer : mVideoConsumers) {
        consumer.onApplicationDisconnected(errorCode);
    }
    if (mMediaRouter != null) {
        LOGD(TAG, "onApplicationDisconnected(): Cached RouteInfo: " + getRouteInfo());
        LOGD(TAG, "onApplicationDisconnected(): Selected RouteInfo: " + mMediaRouter.getSelectedRoute());
        if (getRouteInfo() == null || mMediaRouter.getSelectedRoute().equals(getRouteInfo())) {
            LOGD(TAG, "onApplicationDisconnected(): Setting route to default");
            mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
        }
    }
    onDeviceSelected(null, /* CastDevice */
    null);
    updateMiniControllersVisibility(false);
    stopNotificationService();
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer)

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