Search in sources :

Example 6 with NoConnectionException

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

the class VideoCastManager method updateMediaSession.

/*
     * Updates the playback status of the Media Session
     */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateMediaSession(boolean playing) {
    if (!isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
        return;
    }
    if (!isConnected()) {
        return;
    }
    try {
        if ((mMediaSessionCompat == null) && playing) {
            setUpMediaSession(getRemoteMediaInformation());
        }
        if (mMediaSessionCompat != null) {
            int playState = isRemoteStreamLive() ? PlaybackStateCompat.STATE_BUFFERING : PlaybackStateCompat.STATE_PLAYING;
            int state = playing ? playState : PlaybackStateCompat.STATE_PAUSED;
            PendingIntent pi = getCastControllerPendingIntent();
            if (pi != null) {
                mMediaSessionCompat.setSessionActivity(pi);
            }
            mMediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder().setState(state, 0, 1.0f).setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE).build());
        }
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "Failed to set up MediaSessionCompat due to network issues", e);
    }
}
Also used : NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) Builder(com.google.android.gms.cast.Cast.CastOptions.Builder) PendingIntent(android.app.PendingIntent) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Example 7 with NoConnectionException

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

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 8 with NoConnectionException

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

the class VideoCastControllerFragment method updatePlayerStatus.

private void updatePlayerStatus() {
    int mediaStatus = mCastManager.getPlaybackStatus();
    mMediaStatus = mCastManager.getMediaStatus();
    LOGD(TAG, "updatePlayerStatus(), state: " + mediaStatus);
    if (mSelectedMedia == null) {
        return;
    }
    mCastController.setStreamType(mSelectedMedia.getStreamType());
    if (mediaStatus == MediaStatus.PLAYER_STATE_BUFFERING) {
        mCastController.setSubTitle(getString(R.string.ccl_loading));
    } else {
        mCastController.setSubTitle(getString(R.string.ccl_casting_to_device, mCastManager.getDeviceName()));
    }
    switch(mediaStatus) {
        case MediaStatus.PLAYER_STATE_PLAYING:
            mIsFresh = false;
            if (mPlaybackState != MediaStatus.PLAYER_STATE_PLAYING) {
                mPlaybackState = MediaStatus.PLAYER_STATE_PLAYING;
                mCastController.setPlaybackStatus(mPlaybackState);
            }
            break;
        case MediaStatus.PLAYER_STATE_PAUSED:
            mIsFresh = false;
            if (mPlaybackState != MediaStatus.PLAYER_STATE_PAUSED) {
                mPlaybackState = MediaStatus.PLAYER_STATE_PAUSED;
                mCastController.setPlaybackStatus(mPlaybackState);
            }
            break;
        case MediaStatus.PLAYER_STATE_BUFFERING:
            mIsFresh = false;
            if (mPlaybackState != MediaStatus.PLAYER_STATE_BUFFERING) {
                mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
                mCastController.setPlaybackStatus(mPlaybackState);
            }
            break;
        case MediaStatus.PLAYER_STATE_IDLE:
            LOGD(TAG, "Idle Reason: " + (mCastManager.getIdleReason()));
            switch(mCastManager.getIdleReason()) {
                case MediaStatus.IDLE_REASON_FINISHED:
                    if (!mIsFresh && (mMediaStatus == null || mMediaStatus.getLoadingItemId() == MediaQueueItem.INVALID_ITEM_ID)) {
                        mCastController.closeActivity();
                    }
                    break;
                case MediaStatus.IDLE_REASON_CANCELED:
                    try {
                        if (mCastManager.isRemoteStreamLive()) {
                            if (mPlaybackState != MediaStatus.PLAYER_STATE_IDLE) {
                                mPlaybackState = MediaStatus.PLAYER_STATE_IDLE;
                                mCastController.setPlaybackStatus(mPlaybackState);
                            }
                        } else {
                            mCastController.closeActivity();
                        }
                    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
                        LOGD(TAG, "Failed to determine if stream is live", e);
                    }
                    break;
                case MediaStatus.IDLE_REASON_INTERRUPTED:
                    mPlaybackState = MediaStatus.PLAYER_STATE_IDLE;
                    mCastController.setPlaybackStatus(mPlaybackState);
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}
Also used : NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) Point(android.graphics.Point)

Example 9 with NoConnectionException

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

the class CastManager method setStreamVolume.

/**
     * Sets the stream volume.
     *
     * @param volume Should be a value between 0 and 1, inclusive.
     * @throws NoConnectionException
     * @throws TransientNetworkDisconnectionException
     * @throws CastException If setting system volume fails
     */
public void setStreamVolume(double volume) throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    if (volume > 1.0) {
        volume = 1.0;
    } else if (volume < 0) {
        volume = 0.0;
    }
    RemoteMediaPlayer mediaPlayer = getRemoteMediaPlayer();
    if (mediaPlayer == null) {
        throw new NoConnectionException();
    }
    mediaPlayer.setStreamVolume(mApiClient, volume).setResultCallback((result) -> {
        if (!result.getStatus().isSuccess()) {
            onFailed(R.string.cast_failed_setting_volume, result.getStatus().getStatusCode());
        } else {
            CastManager.this.onStreamVolumeChanged();
        }
    });
}
Also used : RemoteMediaPlayer(com.google.android.gms.cast.RemoteMediaPlayer) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)

Example 10 with NoConnectionException

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

the class RemotePSMP method endPlayback.

@Override
protected Future<?> endPlayback(boolean hasEnded, boolean wasSkipped, boolean shouldContinue, boolean toStoppedState) {
    Log.d(TAG, "endPlayback() called");
    boolean isPlaying = playerStatus == PlayerStatus.PLAYING;
    if (playerStatus != PlayerStatus.INDETERMINATE) {
        setPlayerStatus(PlayerStatus.INDETERMINATE, media);
    }
    if (media != null && wasSkipped) {
        // current position only really matters when we skip
        int position = getPosition();
        if (position >= 0) {
            media.setPosition(position);
        }
    }
    final Playable currentMedia = media;
    Playable nextMedia = null;
    if (shouldContinue) {
        nextMedia = callback.getNextInQueue(currentMedia);
        boolean playNextEpisode = isPlaying && nextMedia != null && UserPreferences.isFollowQueue();
        if (playNextEpisode) {
            Log.d(TAG, "Playback of next episode will start immediately.");
        } else if (nextMedia == null) {
            Log.d(TAG, "No more episodes available to play");
        } else {
            Log.d(TAG, "Loading next episode, but not playing automatically.");
        }
        if (nextMedia != null) {
            callback.onPlaybackEnded(nextMedia.getMediaType(), !playNextEpisode);
            // setting media to null signals to playMediaObject() that we're taking care of post-playback processing
            media = null;
            playMediaObject(nextMedia, false, true, /*TODO for now we always stream*/
            playNextEpisode, playNextEpisode);
        }
    }
    if (shouldContinue || toStoppedState) {
        boolean shouldPostProcess = true;
        if (nextMedia == null) {
            try {
                castMgr.stop();
                shouldPostProcess = false;
            } catch (CastException | TransientNetworkDisconnectionException | NoConnectionException e) {
                Log.e(TAG, "Unable to stop playback", e);
                callback.onPlaybackEnded(null, true);
                stop();
            }
        }
        if (shouldPostProcess) {
            // Otherwise we rely on the chromecast callback to tell us the playback has stopped.
            callback.onPostPlayback(currentMedia, hasEnded, wasSkipped, nextMedia != null);
        }
    } else if (isPlaying) {
        callback.onPlaybackPause(currentMedia, currentMedia != null ? currentMedia.getPosition() : INVALID_TIME);
    }
    FutureTask<?> future = new FutureTask<>(() -> {
    }, null);
    future.run();
    return future;
}
Also used : FutureTask(java.util.concurrent.FutureTask) Playable(de.danoeh.antennapod.core.util.playback.Playable) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

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