Search in sources :

Example 6 with MediaQueueItem

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

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

the class CastManager method onRemoteMediaPlayerStatusUpdated.

/*
     * This is called by onStatusUpdated() of the RemoteMediaPlayer
     */
private void onRemoteMediaPlayerStatusUpdated() {
    Log.d(TAG, "onRemoteMediaPlayerStatusUpdated() reached");
    if (mApiClient == null || remoteMediaPlayer == null) {
        Log.d(TAG, "mApiClient or remoteMediaPlayer is null, so will not proceed");
        return;
    }
    mediaStatus = remoteMediaPlayer.getMediaStatus();
    if (mediaStatus == null) {
        Log.d(TAG, "MediaStatus is null, so will not proceed");
        return;
    } else {
        List<MediaQueueItem> queueItems = mediaStatus.getQueueItems();
        if (queueItems != null) {
            int itemId = mediaStatus.getCurrentItemId();
            MediaQueueItem item = mediaStatus.getQueueItemById(itemId);
            int repeatMode = mediaStatus.getQueueRepeatMode();
            onQueueUpdated(queueItems, item, repeatMode, false);
        } else {
            onQueueUpdated(null, null, MediaStatus.REPEAT_MODE_REPEAT_OFF, false);
        }
        state = mediaStatus.getPlayerState();
        idleReason = mediaStatus.getIdleReason();
        if (state == MediaStatus.PLAYER_STATE_PLAYING) {
            Log.d(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = playing");
        } else if (state == MediaStatus.PLAYER_STATE_PAUSED) {
            Log.d(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = paused");
        } else if (state == MediaStatus.PLAYER_STATE_IDLE) {
            Log.d(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = IDLE with reason: " + idleReason);
            if (idleReason == MediaStatus.IDLE_REASON_ERROR) {
                // something bad happened on the cast device
                Log.d(TAG, "onRemoteMediaPlayerStatusUpdated(): IDLE reason = ERROR");
                onFailed(R.string.cast_failed_receiver_player_error, NO_STATUS_CODE);
            }
        } else if (state == MediaStatus.PLAYER_STATE_BUFFERING) {
            Log.d(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = buffering");
        } else {
            Log.d(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = unknown");
        }
    }
    for (CastConsumer consumer : castConsumers) {
        consumer.onRemoteMediaPlayerStatusUpdated();
    }
    if (mediaStatus != null) {
        double volume = mediaStatus.getStreamVolume();
        boolean isMute = mediaStatus.isMute();
        for (CastConsumer consumer : castConsumers) {
            consumer.onStreamVolumeChanged(volume, isMute);
        }
    }
}
Also used : MediaQueueItem(com.google.android.gms.cast.MediaQueueItem)

Example 8 with MediaQueueItem

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

the class CastManager method attachMediaChannel.

private void attachMediaChannel() throws TransientNetworkDisconnectionException, NoConnectionException {
    Log.d(TAG, "attachMediaChannel()");
    checkConnectivity();
    if (remoteMediaPlayer == null) {
        remoteMediaPlayer = new RemoteMediaPlayer();
        remoteMediaPlayer.setOnStatusUpdatedListener(() -> {
            Log.d(TAG, "RemoteMediaPlayer::onStatusUpdated() is reached");
            CastManager.this.onRemoteMediaPlayerStatusUpdated();
        });
        remoteMediaPlayer.setOnPreloadStatusUpdatedListener(() -> {
            Log.d(TAG, "RemoteMediaPlayer::onPreloadStatusUpdated() is reached");
            CastManager.this.onRemoteMediaPreloadStatusUpdated();
        });
        remoteMediaPlayer.setOnMetadataUpdatedListener(() -> {
            Log.d(TAG, "RemoteMediaPlayer::onMetadataUpdated() is reached");
            CastManager.this.onRemoteMediaPlayerMetadataUpdated();
        });
        remoteMediaPlayer.setOnQueueStatusUpdatedListener(() -> {
            Log.d(TAG, "RemoteMediaPlayer::onQueueStatusUpdated() is reached");
            mediaStatus = remoteMediaPlayer.getMediaStatus();
            if (mediaStatus != null && mediaStatus.getQueueItems() != null) {
                List<MediaQueueItem> queueItems = mediaStatus.getQueueItems();
                int itemId = mediaStatus.getCurrentItemId();
                MediaQueueItem item = mediaStatus.getQueueItemById(itemId);
                int repeatMode = mediaStatus.getQueueRepeatMode();
                onQueueUpdated(queueItems, item, repeatMode, false);
            } else {
                onQueueUpdated(null, null, MediaStatus.REPEAT_MODE_REPEAT_OFF, false);
            }
        });
    }
    try {
        Log.d(TAG, "Registering MediaChannel namespace");
        Cast.CastApi.setMessageReceivedCallbacks(mApiClient, remoteMediaPlayer.getNamespace(), remoteMediaPlayer);
    } catch (IOException | IllegalStateException e) {
        Log.e(TAG, "attachMediaChannel()", e);
    }
}
Also used : RemoteMediaPlayer(com.google.android.gms.cast.RemoteMediaPlayer) IOException(java.io.IOException) MediaQueueItem(com.google.android.gms.cast.MediaQueueItem)

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