Search in sources :

Example 21 with NoConnectionException

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

the class VideoCastManager method onRemoteMediaPlayerMetadataUpdated.

/*
     * This is called by onMetadataUpdated() of RemoteMediaPlayer
     */
public void onRemoteMediaPlayerMetadataUpdated() {
    LOGD(TAG, "onRemoteMediaPlayerMetadataUpdated() reached");
    updateMediaSessionMetadata();
    for (VideoCastConsumer consumer : mVideoConsumers) {
        consumer.onRemoteMediaPlayerMetadataUpdated();
    }
    try {
        updateLockScreenImage(getRemoteMediaInformation());
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "Failed to update lock screen metadata due to a network issue", 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 22 with NoConnectionException

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

the class VideoCastManager method onApplicationConnected.

@Override
protected void onApplicationConnected(ApplicationMetadata appMetadata, String applicationStatus, String sessionId, boolean wasLaunched) {
    LOGD(TAG, "onApplicationConnected() reached with sessionId: " + sessionId + ", and mReconnectionStatus=" + mReconnectionStatus);
    if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
        // we have tried to reconnect and successfully launched the app, so
        // it is time to select the route and make the cast icon happy :-)
        List<RouteInfo> routes = mMediaRouter.getRoutes();
        if (routes != null) {
            String routeId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_ROUTE_ID);
            for (RouteInfo routeInfo : routes) {
                if (routeId.equals(routeInfo.getId())) {
                    // found the right route
                    LOGD(TAG, "Found the correct route during reconnection attempt");
                    mReconnectionStatus = RECONNECTION_STATUS_FINALIZED;
                    mMediaRouter.selectRoute(routeInfo);
                    break;
                }
            }
        }
    }
    startNotificationService();
    try {
        attachDataChannel();
        attachMediaChannel();
        mSessionId = sessionId;
        // saving device for future retrieval; we only save the last session info
        mPreferenceAccessor.saveStringToPreference(PREFS_KEY_SESSION_ID, mSessionId);
        mRemoteMediaPlayer.requestStatus(mApiClient).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

            @Override
            public void onResult(MediaChannelResult result) {
                if (!result.getStatus().isSuccess()) {
                    onFailed(R.string.ccl_failed_status_request, result.getStatus().getStatusCode());
                }
            }
        });
        for (VideoCastConsumer consumer : mVideoConsumers) {
            consumer.onApplicationConnected(appMetadata, mSessionId, wasLaunched);
        }
    } catch (TransientNetworkDisconnectionException e) {
        LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
        onFailed(R.string.ccl_failed_no_connection_trans, NO_STATUS_CODE);
    } catch (NoConnectionException e) {
        LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
        onFailed(R.string.ccl_failed_no_connection, NO_STATUS_CODE);
    }
}
Also used : VideoCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) RouteInfo(android.support.v7.media.MediaRouter.RouteInfo)

Example 23 with NoConnectionException

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

the class VideoCastManager method updateMediaSessionMetadata.

/*
     * On ICS and JB, lock screen metadata is one liner: Title - Album Artist - Album. On KitKat, it
     * has two lines: Title , Album Artist - Album
     */
private void updateMediaSessionMetadata() {
    if ((mMediaSessionCompat == null) || !isFeatureEnabled(FEATURE_LOCKSCREEN)) {
        return;
    }
    try {
        MediaInfo info = getRemoteMediaInformation();
        if (info == null) {
            return;
        }
        final MediaMetadata mm = info.getMetadata();
        MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
        MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
        mMediaSessionCompat.setMetadata(newBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mm.getString(MediaMetadata.KEY_TITLE)).putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, mContext.getResources().getString(R.string.ccl_casting_to_device, getDeviceName())).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, info.getStreamDuration()).build());
    } catch (NotFoundException e) {
        LOGE(TAG, "Failed to update Media Session due to resource not found", e);
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "Failed to update Media Session due to network issues", e);
    }
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) MediaInfo(com.google.android.gms.cast.MediaInfo) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) MediaMetadata(com.google.android.gms.cast.MediaMetadata) NotFoundException(android.content.res.Resources.NotFoundException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)

Example 24 with NoConnectionException

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

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();
        // mMediaStatus.isShuffleEnabled();
        boolean shuffle = false;
        onQueueUpdated(queueItems, item, repeatMode, shuffle);
    } else {
        onQueueUpdated(null, null, MediaStatus.REPEAT_MODE_REPEAT_OFF, false);
    }
    int currentItemId = mMediaStatus.getCurrentItemId();
    if (queueItems != null && !queueItems.isEmpty()) {
        for (MediaQueueItem item : queueItems) {
            LOGD(TAG, "[queue] Queue Item is: " + item.toJson());
        }
    }
    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");
            updateMediaSession(false);
            switch(mIdleReason) {
                case MediaStatus.IDLE_REASON_FINISHED:
                    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);
            }
            if (makeUiHidden) {
                stopReconnectionService();
            }
        } else if (mState == MediaStatus.PLAYER_STATE_BUFFERING) {
            LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = buffering");
        } else {
            LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = unknown");
            makeUiHidden = true;
        }
        if (makeUiHidden) {
            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)

Example 25 with NoConnectionException

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

the class VideoCastControllerActivity method loadAndSetupViews.

private void loadAndSetupViews() {
    mPauseDrawable = getResources().getDrawable(R.drawable.ic_pause_circle_white_80dp);
    mPlayDrawable = getResources().getDrawable(R.drawable.ic_play_circle_white_80dp);
    mStopDrawable = getResources().getDrawable(R.drawable.ic_stop_circle_white_80dp);
    mPageView = findViewById(R.id.pageview);
    mPlayPause = (ImageButton) findViewById(R.id.play_pause_toggle);
    mLiveText = (TextView) findViewById(R.id.live_text);
    mStart = (TextView) findViewById(R.id.start_text);
    mEnd = (TextView) findViewById(R.id.end_text);
    mSeekbar = (SeekBar) findViewById(R.id.seekbar);
    mLine2 = (TextView) findViewById(R.id.textview2);
    mLoading = (ProgressBar) findViewById(R.id.progressbar1);
    mControllers = findViewById(R.id.controllers);
    mClosedCaptionIcon = (ImageButton) findViewById(R.id.cc);
    mSkipNext = (ImageButton) findViewById(R.id.next);
    mSkipPrevious = (ImageButton) findViewById(R.id.previous);
    mPlaybackControls = findViewById(R.id.playback_controls);
    mMini = (MiniController) findViewById(R.id.miniController1);
    mMini.setCurrentVisibility(false);
    setClosedCaptionState(CC_DISABLED);
    mPlayPause.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                mListener.onPlayPauseClicked(v);
            } catch (TransientNetworkDisconnectionException e) {
                LOGE(TAG, "Failed to toggle playback due to temporary network issue", e);
                Utils.showToast(VideoCastControllerActivity.this, R.string.ccl_failed_no_connection_trans);
            } catch (NoConnectionException e) {
                LOGE(TAG, "Failed to toggle playback due to network issues", e);
                Utils.showToast(VideoCastControllerActivity.this, R.string.ccl_failed_no_connection);
            } catch (Exception e) {
                LOGE(TAG, "Failed to toggle playback due to other issues", e);
                Utils.showToast(VideoCastControllerActivity.this, R.string.ccl_failed_perform_action);
            }
        }
    });
    mSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            try {
                if (mListener != null) {
                    mListener.onStopTrackingTouch(seekBar);
                }
            } catch (Exception e) {
                LOGE(TAG, "Failed to complete seek", e);
                finish();
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            try {
                if (mListener != null) {
                    mListener.onStartTrackingTouch(seekBar);
                }
            } catch (Exception e) {
                LOGE(TAG, "Failed to start seek", e);
                finish();
            }
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mStart.setText(Utils.formatMillis(progress));
            try {
                if (mListener != null) {
                    mListener.onProgressChanged(seekBar, progress, fromUser);
                }
            } catch (Exception e) {
                LOGE(TAG, "Failed to set the progress result", e);
            }
        }
    });
    mClosedCaptionIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                showTracksChooserDialog();
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "Failed to get the media", e);
            }
        }
    });
    mSkipNext.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                mListener.onSkipNextClicked(v);
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "Failed to move to the next item in the queue", e);
            }
        }
    });
    mSkipPrevious.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                mListener.onSkipPreviousClicked(v);
            } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                LOGE(TAG, "Failed to move to the previous item in the queue", e);
            }
        }
    });
}
Also used : SeekBar(android.widget.SeekBar) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) OnClickListener(android.view.View.OnClickListener) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)

Aggregations

NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)27 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)23 VideoCastConsumer (com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer)8 MediaInfo (com.google.android.gms.cast.MediaInfo)7 SuppressLint (android.annotation.SuppressLint)5 MediaMetadata (com.google.android.gms.cast.MediaMetadata)4 Point (android.graphics.Point)3 Builder (com.google.android.gms.cast.Cast.CastOptions.Builder)3 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)3 TargetApi (android.annotation.TargetApi)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 NotFoundException (android.content.res.Resources.NotFoundException)2 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)2 RouteInfo (android.support.v7.media.MediaRouter.RouteInfo)2 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 SeekBar (android.widget.SeekBar)2 OnSeekBarChangeListener (android.widget.SeekBar.OnSeekBarChangeListener)2