Search in sources :

Example 1 with MediaQueue

use of com.google.android.libraries.cast.companionlibrary.cast.MediaQueue in project AntennaPod by AntennaPod.

the class CastManager method onQueueUpdated.

/*
    * This is called by onQueueStatusUpdated() of RemoteMediaPlayer
    */
private void onQueueUpdated(List<MediaQueueItem> queueItems, MediaQueueItem item, int repeatMode, boolean shuffle) {
    Log.d(TAG, "onQueueUpdated() reached");
    Log.d(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) {
        mediaQueue = new MediaQueue(new CopyOnWriteArrayList<>(queueItems), item, shuffle, repeatMode);
    } else {
        mediaQueue = new MediaQueue(new CopyOnWriteArrayList<>(), null, false, MediaStatus.REPEAT_MODE_REPEAT_OFF);
    }
    for (CastConsumer consumer : castConsumers) {
        consumer.onMediaQueueUpdated(queueItems, item, repeatMode, shuffle);
    }
}
Also used : MediaQueue(com.google.android.libraries.cast.companionlibrary.cast.MediaQueue) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with MediaQueue

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

the class VideoCastControllerFragment method onReady.

/**
 * Loads the media on the cast device.
 *
 * @param mediaInfo The media to be loaded
 * @param shouldStartPlayback If {@code true}, playback starts after load automatically
 * @param startPoint The position to start the play back
 * @param customData An optional custom data to be sent along the load api; it can be
 * {@code null}
 */
private void onReady(MediaInfo mediaInfo, boolean shouldStartPlayback, int startPoint, JSONObject customData) {
    mSelectedMedia = mediaInfo;
    updateClosedCaptionState();
    try {
        mCastController.setStreamType(mSelectedMedia.getStreamType());
        if (shouldStartPlayback) {
            // need to start remote playback
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            mCastController.setPlaybackStatus(mPlaybackState);
            mCastManager.loadMedia(mSelectedMedia, true, startPoint, customData);
        } else {
            // we don't change the status of remote playback
            if (mCastManager.isRemoteMediaPlaying()) {
                mPlaybackState = MediaStatus.PLAYER_STATE_PLAYING;
            } else {
                mPlaybackState = MediaStatus.PLAYER_STATE_PAUSED;
            }
            mCastController.setPlaybackStatus(mPlaybackState);
        }
    } catch (Exception e) {
        LOGE(TAG, "Failed to get playback and media information", e);
        mCastController.closeActivity();
    }
    MediaQueue mediaQueue = mCastManager.getMediaQueue();
    int size = 0;
    int position = 0;
    if (mediaQueue != null) {
        size = mediaQueue.getCount();
        position = mediaQueue.getCurrentItemPosition();
    }
    mCastController.onQueueItemsUpdated(size, position);
    updateMetadata();
    restartTrickplayTimer();
}
Also used : MediaQueue(com.google.android.libraries.cast.companionlibrary.cast.MediaQueue) JSONException(org.json.JSONException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException) Point(android.graphics.Point)

Example 3 with MediaQueue

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

the class VideoCastNotificationService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mDimensionInPixels = Utils.convertDpToPixel(VideoCastNotificationService.this, getResources().getDimension(R.dimen.ccl_notification_image_size));
    mCastManager = VideoCastManager.getInstance();
    readPersistedData();
    if (!mCastManager.isConnected() && !mCastManager.isConnecting()) {
        mCastManager.reconnectSessionIfPossible();
    }
    MediaQueue mediaQueue = mCastManager.getMediaQueue();
    if (mediaQueue != null) {
        int position = mediaQueue.getCurrentItemPosition();
        int size = mediaQueue.getCount();
        mHasNext = position < (size - 1);
        mHasPrev = position > 0;
    }
    mConsumer = new VideoCastConsumerImpl() {

        @Override
        public void onApplicationDisconnected(int errorCode) {
            LOGD(TAG, "onApplicationDisconnected() was reached, stopping the notification" + " service");
            stopSelf();
        }

        @Override
        public void onDisconnected() {
            stopSelf();
        }

        @Override
        public void onRemoteMediaPlayerStatusUpdated() {
            int mediaStatus = mCastManager.getPlaybackStatus();
            VideoCastNotificationService.this.onRemoteMediaPlayerStatusUpdated(mediaStatus);
        }

        @Override
        public void onUiVisibilityChanged(boolean visible) {
            mVisible = !visible;
            if (mNotification == null) {
                try {
                    setUpNotification(mCastManager.getRemoteMediaInformation());
                } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                    LOGE(TAG, "onStartCommand() failed to get media", e);
                }
            }
            if (mVisible && (mNotification != null)) {
                startForeground(NOTIFICATION_ID, mNotification);
            } else {
                stopForeground(true);
            }
        }

        @Override
        public void onMediaQueueUpdated(List<MediaQueueItem> queueItems, MediaQueueItem item, int repeatMode, boolean shuffle) {
            int size = 0;
            int position = 0;
            if (queueItems != null) {
                size = queueItems.size();
                position = queueItems.indexOf(item);
            }
            mHasNext = position < (size - 1);
            mHasPrev = position > 0;
        }
    };
    mCastManager.addVideoCastConsumer(mConsumer);
    mNotificationActions = mCastManager.getCastConfiguration().getNotificationActions();
    List<Integer> notificationCompactActions = mCastManager.getCastConfiguration().getNotificationCompactActions();
    if (notificationCompactActions != null) {
        mNotificationCompactActionsArray = new int[notificationCompactActions.size()];
        for (int i = 0; i < notificationCompactActions.size(); i++) {
            mNotificationCompactActionsArray[i] = notificationCompactActions.get(i);
        }
    }
    mForwardTimeInMillis = TimeUnit.SECONDS.toMillis(mCastManager.getCastConfiguration().getForwardStep());
}
Also used : MediaQueue(com.google.android.libraries.cast.companionlibrary.cast.MediaQueue) MediaQueueItem(com.google.android.gms.cast.MediaQueueItem) VideoCastConsumerImpl(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl)

Example 4 with MediaQueue

use of com.google.android.libraries.cast.companionlibrary.cast.MediaQueue in project zype-android by zype.

the class VideoCastControllerFragment method onReady.

/**
 * Loads the media on the cast device.
 *
 * @param mediaInfo The media to be loaded
 * @param shouldStartPlayback If {@code true}, playback starts after load automatically
 * @param startPoint The position to start the play back
 * @param customData An optional custom data to be sent along the load api; it can be
 * {@code null}
 */
private void onReady(MediaInfo mediaInfo, boolean shouldStartPlayback, int startPoint, JSONObject customData) {
    mSelectedMedia = mediaInfo;
    updateClosedCaptionState();
    try {
        mCastController.setStreamType(mSelectedMedia.getStreamType());
        if (shouldStartPlayback) {
            // need to start remote playback
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            mCastController.setPlaybackStatus(mPlaybackState);
            mCastManager.loadMedia(mSelectedMedia, true, startPoint, customData);
        } else {
            // we don't change the status of remote playback
            if (mCastManager.isRemoteMediaPlaying()) {
                mPlaybackState = MediaStatus.PLAYER_STATE_PLAYING;
            } else {
                mPlaybackState = MediaStatus.PLAYER_STATE_PAUSED;
            }
            mCastController.setPlaybackStatus(mPlaybackState);
        }
    } catch (Exception e) {
        LOGE(TAG, "Failed to get playback and media information", e);
        mCastController.closeActivity();
    }
    MediaQueue mediaQueue = mCastManager.getMediaQueue();
    int size = 0;
    int position = 0;
    if (mediaQueue != null) {
        size = mediaQueue.getCount();
        position = mediaQueue.getCurrentItemPosition();
    }
    mCastController.onQueueItemsUpdated(size, position);
    updateMetadata();
    restartTrickplayTimer();
}
Also used : MediaQueue(com.google.android.libraries.cast.companionlibrary.cast.MediaQueue) JSONException(org.json.JSONException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Example 5 with MediaQueue

use of com.google.android.libraries.cast.companionlibrary.cast.MediaQueue in project zype-android by zype.

the class VideoCastControllerFragment method onReady.

/**
 * Loads the media on the cast device.
 *
 * @param mediaInfo The media to be loaded
 * @param shouldStartPlayback If {@code true}, playback starts after load automatically
 * @param startPoint The position to start the play back
 * @param customData An optional custom data to be sent along the load api; it can be
 * {@code null}
 */
private void onReady(MediaInfo mediaInfo, boolean shouldStartPlayback, int startPoint, JSONObject customData) {
    mSelectedMedia = mediaInfo;
    updateClosedCaptionState();
    try {
        mCastController.setStreamType(mSelectedMedia.getStreamType());
        if (shouldStartPlayback) {
            // need to start remote playback
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            mCastController.setPlaybackStatus(mPlaybackState);
            mCastManager.loadMedia(mSelectedMedia, true, startPoint, customData);
        } else {
            // we don't change the status of remote playback
            if (mCastManager.isRemoteMediaPlaying()) {
                mPlaybackState = MediaStatus.PLAYER_STATE_PLAYING;
            } else {
                mPlaybackState = MediaStatus.PLAYER_STATE_PAUSED;
            }
            mCastController.setPlaybackStatus(mPlaybackState);
        }
    } catch (Exception e) {
        LOGE(TAG, "Failed to get playback and media information", e);
        mCastController.closeActivity();
    }
    MediaQueue mediaQueue = mCastManager.getMediaQueue();
    int size = 0;
    int position = 0;
    if (mediaQueue != null) {
        size = mediaQueue.getCount();
        position = mediaQueue.getCurrentItemPosition();
    }
    mCastController.onQueueItemsUpdated(size, position);
    updateMetadata();
    restartTrickplayTimer();
}
Also used : MediaQueue(com.google.android.libraries.cast.companionlibrary.cast.MediaQueue) JSONException(org.json.JSONException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Aggregations

MediaQueue (com.google.android.libraries.cast.companionlibrary.cast.MediaQueue)5 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)3 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)3 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)3 JSONException (org.json.JSONException)3 Point (android.graphics.Point)1 MediaQueueItem (com.google.android.gms.cast.MediaQueueItem)1 VideoCastConsumerImpl (com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1