Search in sources :

Example 6 with FetchBitmapTask

use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project zype-android by zype.

the class VideoCastNotificationService method setUpNotification.

private void setUpNotification(final MediaInfo info) throws TransientNetworkDisconnectionException, NoConnectionException {
    if (info == null) {
        return;
    }
    if (mBitmapDecoderTask != null) {
        mBitmapDecoderTask.cancel(false);
    }
    Uri imgUri = null;
    try {
        if (!info.getMetadata().hasImages()) {
            build(info, null, mIsPlaying);
            return;
        } else {
            imgUri = info.getMetadata().getImages().get(0).getUrl();
        }
    } catch (CastException e) {
        LOGE(TAG, "Failed to build notification", e);
    }
    mBitmapDecoderTask = new FetchBitmapTask() {

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            try {
                mVideoArtBitmap = Utils.scaleAndCenterCropBitmap(bitmap, mDimensionInPixels, mDimensionInPixels);
                build(info, mVideoArtBitmap, mIsPlaying);
            } catch (CastException | NoConnectionException | TransientNetworkDisconnectionException e) {
                LOGE(TAG, "Failed to set notification for " + info.toString(), e);
            }
            if (mVisible && (mNotification != null)) {
                startForeground(NOTIFICATION_ID, mNotification);
            }
            if (this == mBitmapDecoderTask) {
                mBitmapDecoderTask = null;
            }
        }
    };
    mBitmapDecoderTask.execute(imgUri);
}
Also used : Bitmap(android.graphics.Bitmap) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask) Uri(android.net.Uri) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Example 7 with FetchBitmapTask

use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project zype-android by zype.

the class MiniController method setUpcomingIcon.

private void setUpcomingIcon(Uri uri) {
    if (mUpcomingIconUri != null && mUpcomingIconUri.equals(uri)) {
        return;
    }
    mUpcomingIconUri = uri;
    if (mFetchUpcomingBitmapTask != null) {
        mFetchUpcomingBitmapTask.cancel(true);
    }
    mFetchUpcomingBitmapTask = new FetchBitmapTask() {

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            if (bitmap == null) {
                bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.album_art_placeholder);
            }
            setUpcomingIcon(bitmap);
            if (this == mFetchUpcomingBitmapTask) {
                mFetchUpcomingBitmapTask = null;
            }
        }
    };
    mFetchUpcomingBitmapTask.execute(uri);
}
Also used : Bitmap(android.graphics.Bitmap) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)

Example 8 with FetchBitmapTask

use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project Shuttle by timusus.

the class VideoCastManager method setBitmapForLockScreen.

/*
     * Sets the appropriate {@link Bitmap} for the right size image for lock screen. In ICS and
     * JB, the image shown on the lock screen is a small size bitmap but for KitKat, the image is a
     * full-screen image so we need to separately handle these two cases.
     */
private void setBitmapForLockScreen(MediaInfo video) {
    if (video == null || mMediaSessionCompat == null) {
        return;
    }
    Uri imgUrl = null;
    Bitmap bm = null;
    List<WebImage> images = video.getMetadata().getImages();
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (images.size() > 1) {
            imgUrl = images.get(1).getUrl();
        } else if (images.size() == 1) {
            imgUrl = images.get(0).getUrl();
        } else if (mContext != null) {
            // we don't have a url for image so get a placeholder image from resources
            bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder_large);
        }
    } else if (!images.isEmpty()) {
        imgUrl = images.get(0).getUrl();
    } else {
        // we don't have a url for image so get a placeholder image from resources
        bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder);
    }
    if (bm != 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_ART, bm).build());
    } else {
        if (mLockScreenFetchTask != null) {
            mLockScreenFetchTask.cancel(true);
        }
        Point screenSize = Utils.getDisplaySize(mContext);
        mLockScreenFetchTask = new FetchBitmapTask(screenSize.x, screenSize.y, false) {

            @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_ART, bitmap).build());
                }
                mLockScreenFetchTask = null;
            }
        };
        mLockScreenFetchTask.execute(imgUrl);
    }
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) Bitmap(android.graphics.Bitmap) Builder(com.google.android.gms.cast.Cast.CastOptions.Builder) WebImage(com.google.android.gms.common.images.WebImage) Point(android.graphics.Point) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask) Uri(android.net.Uri)

Example 9 with FetchBitmapTask

use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project Shuttle by timusus.

the class VideoMediaRouteControllerDialog method setIcon.

public void setIcon(Uri uri) {
    if (mIconUri != null && mIconUri.equals(uri)) {
        return;
    }
    mIconUri = uri;
    if (uri == null) {
        Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder);
        mIcon.setImageBitmap(bm);
        return;
    }
    if (mFetchBitmap != null) {
        mFetchBitmap.cancel(true);
    }
    mFetchBitmap = new FetchBitmapTask() {

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            mIcon.setImageBitmap(bitmap);
            if (this == mFetchBitmap) {
                mFetchBitmap = null;
            }
        }
    };
    mFetchBitmap.execute(mIconUri);
}
Also used : Bitmap(android.graphics.Bitmap) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)

Example 10 with FetchBitmapTask

use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project Shuttle by timusus.

the class VideoCastNotificationService method setUpNotification.

private void setUpNotification(final MediaInfo info) throws TransientNetworkDisconnectionException, NoConnectionException {
    if (info == null) {
        return;
    }
    if (mBitmapDecoderTask != null) {
        mBitmapDecoderTask.cancel(false);
    }
    Uri imgUri = null;
    try {
        if (!info.getMetadata().hasImages()) {
            build(info, null, mIsPlaying);
            return;
        } else {
            imgUri = info.getMetadata().getImages().get(0).getUrl();
        }
    } catch (CastException e) {
        LOGE(TAG, "Failed to build notification", e);
    }
    mBitmapDecoderTask = new FetchBitmapTask() {

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            try {
                mVideoArtBitmap = Utils.scaleAndCenterCropBitmap(bitmap, mDimensionInPixels, mDimensionInPixels);
                build(info, mVideoArtBitmap, mIsPlaying);
            } catch (CastException | NoConnectionException | TransientNetworkDisconnectionException e) {
                LOGE(TAG, "Failed to set notification for " + info.toString(), e);
            }
            if (mVisible && (mNotification != null)) {
                startForeground(NOTIFICATION_ID, mNotification);
            }
            if (this == mBitmapDecoderTask) {
                mBitmapDecoderTask = null;
            }
        }
    };
    mBitmapDecoderTask.execute(imgUri);
}
Also used : Bitmap(android.graphics.Bitmap) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask) Uri(android.net.Uri) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Aggregations

Bitmap (android.graphics.Bitmap)14 FetchBitmapTask (com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)14 Uri (android.net.Uri)5 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)3 Builder (com.google.android.gms.cast.Cast.CastOptions.Builder)3 Point (android.graphics.Point)2 WebImage (com.google.android.gms.common.images.WebImage)2 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)2 NotFoundException (android.content.res.Resources.NotFoundException)1 MediaInfo (com.google.android.gms.cast.MediaInfo)1 MediaMetadata (com.google.android.gms.cast.MediaMetadata)1 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)1 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)1