Search in sources :

Example 1 with MediaQueueItem

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

the class VideoCastManager method attachMediaChannel.

private void attachMediaChannel() throws TransientNetworkDisconnectionException, NoConnectionException {
    LOGD(TAG, "attachMediaChannel()");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        mRemoteMediaPlayer = new RemoteMediaPlayer();
        mRemoteMediaPlayer.setOnStatusUpdatedListener(new RemoteMediaPlayer.OnStatusUpdatedListener() {

            @Override
            public void onStatusUpdated() {
                LOGD(TAG, "RemoteMediaPlayer::onStatusUpdated() is reached");
                VideoCastManager.this.onRemoteMediaPlayerStatusUpdated();
            }
        });
        mRemoteMediaPlayer.setOnPreloadStatusUpdatedListener(new RemoteMediaPlayer.OnPreloadStatusUpdatedListener() {

            @Override
            public void onPreloadStatusUpdated() {
                LOGD(TAG, "RemoteMediaPlayer::onPreloadStatusUpdated() is " + "reached");
                VideoCastManager.this.onRemoteMediaPreloadStatusUpdated();
            }
        });
        mRemoteMediaPlayer.setOnMetadataUpdatedListener(new RemoteMediaPlayer.OnMetadataUpdatedListener() {

            @Override
            public void onMetadataUpdated() {
                LOGD(TAG, "RemoteMediaPlayer::onMetadataUpdated() is reached");
                VideoCastManager.this.onRemoteMediaPlayerMetadataUpdated();
            }
        });
        mRemoteMediaPlayer.setOnQueueStatusUpdatedListener(new RemoteMediaPlayer.OnQueueStatusUpdatedListener() {

            @Override
            public void onQueueStatusUpdated() {
                LOGD(TAG, "RemoteMediaPlayer::onQueueStatusUpdated() is reached");
                mMediaStatus = mRemoteMediaPlayer != null ? mRemoteMediaPlayer.getMediaStatus() : null;
                if (mMediaStatus != null && mMediaStatus.getQueueItems() != null) {
                    List<MediaQueueItem> queueItems = mMediaStatus.getQueueItems();
                    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);
                }
            }
        });
    }
    try {
        LOGD(TAG, "Registering MediaChannel namespace");
        Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer);
    } catch (IOException | IllegalStateException e) {
        LOGE(TAG, "attachMediaChannel()", e);
    }
    setUpMediaSession(null);
}
Also used : RemoteMediaPlayer(com.google.android.gms.cast.RemoteMediaPlayer) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IOException(java.io.IOException) MediaQueueItem(com.google.android.gms.cast.MediaQueueItem)

Example 2 with MediaQueueItem

use of com.google.android.gms.cast.MediaQueueItem 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 3 with MediaQueueItem

use of com.google.android.gms.cast.MediaQueueItem in project AntennaPod by AntennaPod.

the class CastManager method onRemoteMediaPreloadStatusUpdated.

private void onRemoteMediaPreloadStatusUpdated() {
    MediaQueueItem item = null;
    mediaStatus = remoteMediaPlayer.getMediaStatus();
    if (mediaStatus != null) {
        item = mediaStatus.getQueueItemById(mediaStatus.getPreloadedItemId());
    }
    preLoadingItem = item;
    Log.d(TAG, "onRemoteMediaPreloadStatusUpdated() " + item);
    for (CastConsumer consumer : castConsumers) {
        consumer.onRemoteMediaPreloadStatusUpdated(item);
    }
}
Also used : MediaQueueItem(com.google.android.gms.cast.MediaQueueItem)

Example 4 with MediaQueueItem

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

the class Utils method rebuildQueueAndAppend.

/**
     * Given a list of queue items, and a new item, this method recreates an identical list of items
     * from the queue, except that the {@code itemId} of each item is erased, in effect preparing
     * the list to be reloaded. Then, it appends the new item to teh end of the rebuilt list and
     * returns the result.
     */
public static MediaQueueItem[] rebuildQueueAndAppend(List<MediaQueueItem> items, MediaQueueItem currentItem) {
    if (items == null || items.isEmpty()) {
        return new MediaQueueItem[] { currentItem };
    }
    MediaQueueItem[] rebuiltQueue = new MediaQueueItem[items.size() + 1];
    for (int i = 0; i < items.size(); i++) {
        rebuiltQueue[i] = rebuildQueueItem(items.get(i));
    }
    rebuiltQueue[items.size()] = currentItem;
    return rebuiltQueue;
}
Also used : MediaQueueItem(com.google.android.gms.cast.MediaQueueItem) Point(android.graphics.Point)

Example 5 with MediaQueueItem

use of com.google.android.gms.cast.MediaQueueItem 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)

Aggregations

MediaQueueItem (com.google.android.gms.cast.MediaQueueItem)8 Point (android.graphics.Point)2 RemoteMediaPlayer (com.google.android.gms.cast.RemoteMediaPlayer)2 VideoCastConsumer (com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer)2 IOException (java.io.IOException)2 SuppressLint (android.annotation.SuppressLint)1 MediaQueue (com.google.android.libraries.cast.companionlibrary.cast.MediaQueue)1 VideoCastConsumerImpl (com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl)1 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)1 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1