Search in sources :

Example 1 with MediaInfo

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

use of com.google.android.gms.cast.MediaInfo in project Shuttle by timusus.

the class VideoCastManager method isRemoteStreamLive.

/**
     * Determines if the media that is loaded remotely is a live stream or not.
     *
     * @throws TransientNetworkDisconnectionException
     * @throws NoConnectionException
     */
public final boolean isRemoteStreamLive() throws TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    MediaInfo info = getRemoteMediaInformation();
    return (info != null) && (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE);
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo)

Example 3 with MediaInfo

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

Example 4 with MediaInfo

use of com.google.android.gms.cast.MediaInfo in project Shuttle by timusus.

the class VideoCastManager method getRemoteMediaUrl.

/**
     * Returns the url for the movie that is currently playing on the remote device. If there is no
     * connection, this will return <code>null</code>.
     *
     * @throws NoConnectionException If no connectivity to the device exists
     * @throws TransientNetworkDisconnectionException If framework is still trying to recover from
     * a possibly transient loss of network
     */
public String getRemoteMediaUrl() throws TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    if (mRemoteMediaPlayer != null && mRemoteMediaPlayer.getMediaInfo() != null) {
        MediaInfo info = mRemoteMediaPlayer.getMediaInfo();
        mRemoteMediaPlayer.getMediaStatus().getPlayerState();
        return info.getContentId();
    }
    throw new NoConnectionException();
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)

Example 5 with MediaInfo

use of com.google.android.gms.cast.MediaInfo in project Shuttle by timusus.

the class VideoCastControllerFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mCastConsumer = new MyCastConsumer();
    Bundle bundle = getArguments();
    if (bundle == null) {
        return;
    }
    Bundle extras = bundle.getBundle(EXTRAS);
    Bundle mediaWrapper = extras.getBundle(VideoCastManager.EXTRA_MEDIA);
    // Retain this fragment across configuration changes.
    setRetainInstance(true);
    mCastManager.addTracksSelectedListener(this);
    boolean explicitStartActivity = mCastManager.getPreferenceAccessor().getBooleanFromPreference(VideoCastManager.PREFS_KEY_START_ACTIVITY, false);
    if (explicitStartActivity) {
        mIsFresh = true;
    }
    mCastManager.getPreferenceAccessor().saveBooleanToPreference(VideoCastManager.PREFS_KEY_START_ACTIVITY, false);
    mCastController.setNextPreviousVisibilityPolicy(mCastManager.getCastConfiguration().getNextPrevVisibilityPolicy());
    if (extras.getBoolean(VideoCastManager.EXTRA_HAS_AUTH)) {
        if (mIsFresh) {
            mOverallState = OverallState.AUTHORIZING;
            mMediaAuthService = mCastManager.getMediaAuthService();
            handleMediaAuthTask(mMediaAuthService);
            showImage(Utils.getImageUri(mMediaAuthService.getMediaInfo(), 1));
        }
    } else if (mediaWrapper != null) {
        mOverallState = OverallState.PLAYBACK;
        boolean shouldStartPlayback = extras.getBoolean(VideoCastManager.EXTRA_SHOULD_START);
        String customDataStr = extras.getString(VideoCastManager.EXTRA_CUSTOM_DATA);
        JSONObject customData = null;
        if (!TextUtils.isEmpty(customDataStr)) {
            try {
                customData = new JSONObject(customDataStr);
            } catch (JSONException e) {
                LOGE(TAG, "Failed to unmarshalize custom data string: customData=" + customDataStr, e);
            }
        }
        MediaInfo info = Utils.bundleToMediaInfo(mediaWrapper);
        int startPoint = extras.getInt(VideoCastManager.EXTRA_START_POINT, 0);
        onReady(info, shouldStartPlayback && explicitStartActivity, startPoint, customData);
    }
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) JSONException(org.json.JSONException)

Aggregations

MediaInfo (com.google.android.gms.cast.MediaInfo)16 MediaMetadata (com.google.android.gms.cast.MediaMetadata)9 WebImage (com.google.android.gms.common.images.WebImage)5 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)5 JSONObject (org.json.JSONObject)4 Uri (android.net.Uri)3 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)3 Calendar (java.util.Calendar)3 JSONException (org.json.JSONException)3 Bitmap (android.graphics.Bitmap)2 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)2 NotFoundException (android.content.res.Resources.NotFoundException)1 SQLiteException (android.database.sqlite.SQLiteException)1 Point (android.graphics.Point)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 Builder (com.google.android.gms.cast.Cast.CastOptions.Builder)1 MediaTrack (com.google.android.gms.cast.MediaTrack)1 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)1 FetchBitmapTask (com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)1