Search in sources :

Example 1 with VideoCastConsumerImpl

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

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

the class BaseCastActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (ShuttleUtils.isUpgraded()) {
        mCastManager = VideoCastManager.getInstance();
    }
    mCastConsumer = new VideoCastConsumerImpl() {

        @Override
        public void onConnectionSuspended(int cause) {
            Log.d(TAG, "onConnectionSuspended() was called with cause: " + cause);
        //Todo: Show toast
        }

        @Override
        public void onConnectivityRecovered() {
        //Todo: Show toast
        }
    };
    if (mCastManager != null) {
        mCastManager.reconnectSessionIfPossible();
    }
}
Also used : VideoCastConsumerImpl(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl)

Example 3 with VideoCastConsumerImpl

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

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();
    }
    mConsumer = new VideoCastConsumerImpl() {

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

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

        @Override
        public void onUiVisibilityChanged(boolean visible) {
            mVisible = !visible;
            if (mVisible && (mNotification != null)) {
                startForeground(NOTIFICATION_ID, mNotification);
            } else {
                stopForeground(true);
            }
        }
    };
    mCastManager.addVideoCastConsumer(mConsumer);
}
Also used : VideoCastConsumerImpl(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl)

Aggregations

VideoCastConsumerImpl (com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl)3 MediaQueueItem (com.google.android.gms.cast.MediaQueueItem)1 MediaQueue (com.google.android.libraries.cast.companionlibrary.cast.MediaQueue)1