Search in sources :

Example 1 with TransientNetworkDisconnectionException

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

the class VideoMediaRouteControllerDialog method updateMetadata.

private void updateMetadata() {
    MediaInfo info;
    try {
        info = mCastManager.getRemoteMediaInformation();
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        hideControls(true, R.string.ccl_failed_no_connection_short);
        return;
    }
    if (info == null) {
        hideControls(true, R.string.ccl_no_media_info);
        return;
    }
    mStreamType = info.getStreamType();
    hideControls(false, 0);
    MediaMetadata mm = info.getMetadata();
    mTitle.setText(mm.getString(MediaMetadata.KEY_TITLE));
    mSubTitle.setText(mm.getString(MediaMetadata.KEY_SUBTITLE));
    setIcon(mm.hasImages() ? mm.getImages().get(0).getUrl() : null);
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) MediaMetadata(com.google.android.gms.cast.MediaMetadata) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)

Example 2 with TransientNetworkDisconnectionException

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

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);
    ((MiniController) findViewById(R.id.miniController1)).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) MiniController(com.google.android.libraries.cast.companionlibrary.widgets.MiniController) 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)

Example 3 with TransientNetworkDisconnectionException

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

the class VideoCastManager method getCastControllerPendingIntent.

/*
     * Returns a PendingIntent that can open the target activity for controlling the cast experience
     */
private PendingIntent getCastControllerPendingIntent() {
    try {
        Bundle mediaWrapper = Utils.mediaInfoToBundle(getRemoteMediaInformation());
        Intent contentIntent = new Intent(mContext, mTargetActivity);
        contentIntent.putExtra(VideoCastManager.EXTRA_MEDIA, mediaWrapper);
        return PendingIntent.getActivity(mContext, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "getCastControllerPendingIntent(): Failed to get the remote media information");
    }
    return null;
}
Also used : NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) Bundle(android.os.Bundle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)

Example 4 with TransientNetworkDisconnectionException

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

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);
    mApplicationErrorCode = NO_APPLICATION_ERROR;
    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 5 with TransientNetworkDisconnectionException

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

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(CastConfiguration.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);
        MediaMetadataCompat metadata = 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())).putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mm.getString(MediaMetadata.KEY_TITLE)).putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, mm.getString(MediaMetadata.KEY_SUBTITLE)).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, info.getStreamDuration()).build();
        mMediaSessionCompat.setMetadata(metadata);
        Uri iconUri = mm.hasImages() ? mm.getImages().get(0).getUrl() : null;
        if (iconUri == null) {
            Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder);
            mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bm).build());
        } else {
            if (mMediaSessionIconFetchTask != null) {
                mMediaSessionIconFetchTask.cancel(true);
            }
            mMediaSessionIconFetchTask = new FetchBitmapTask() {

                @Override
                protected void onPostExecute(Bitmap bitmap) {
                    if (bitmap != null && mMediaSessionCompat != null) {
                        MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
                        MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
                        mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bitmap).build());
                    }
                    mMediaSessionIconFetchTask = null;
                }
            };
            mMediaSessionIconFetchTask.execute(iconUri);
        }
    } 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) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) Builder(com.google.android.gms.cast.Cast.CastOptions.Builder) NotFoundException(android.content.res.Resources.NotFoundException) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) MediaInfo(com.google.android.gms.cast.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)

Aggregations

NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)15 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)15 VideoCastConsumer (com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer)4 SuppressLint (android.annotation.SuppressLint)3 Point (android.graphics.Point)3 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)3 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Builder (com.google.android.gms.cast.Cast.CastOptions.Builder)2 MediaInfo (com.google.android.gms.cast.MediaInfo)2 MediaMetadata (com.google.android.gms.cast.MediaMetadata)2 Playable (de.danoeh.antennapod.core.util.playback.Playable)2 TargetApi (android.annotation.TargetApi)1 NotFoundException (android.content.res.Resources.NotFoundException)1 SQLiteException (android.database.sqlite.SQLiteException)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)1 RouteInfo (android.support.v7.media.MediaRouter.RouteInfo)1