use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask 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);
}
}
use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project Shuttle by timusus.
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);
}
use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project Shuttle by timusus.
the class MiniController method setIcon.
@Override
public void setIcon(Uri uri) {
if (mIconUri != null && mIconUri.equals(uri)) {
return;
}
mIconUri = uri;
if (mFetchBitmapTask != null) {
mFetchBitmapTask.cancel(true);
}
mFetchBitmapTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap == null) {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.album_art_placeholder);
}
setIcon(bitmap);
if (this == mFetchBitmapTask) {
mFetchBitmapTask = null;
}
}
};
mFetchBitmapTask.execute(uri);
}
use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project zype-android by zype.
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_ALBUM_ART, bm).build());
} else {
new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap).build());
}
}.execute(imgUrl);
}
}
use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project zype-android by zype.
the class VideoCastControllerFragment method showImage.
/*
* Gets the image at the given url and populates the image view with that. It tries to cache the
* image to avoid unnecessary network calls.
*/
private void showImage(final Uri uri) {
if (mImageAsyncTask != null) {
mImageAsyncTask.cancel(true);
}
if (uri == null) {
mCastController.setImage(BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.album_art_placeholder_large));
return;
}
if (mUrlAndBitmap != null && mUrlAndBitmap.isMatch(uri)) {
// we can reuse mBitmap
mCastController.setImage(mUrlAndBitmap.mBitmap);
return;
}
mUrlAndBitmap = null;
mImageAsyncTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null) {
mUrlAndBitmap = new UrlAndBitmap();
mUrlAndBitmap.mBitmap = bitmap;
mUrlAndBitmap.mUrl = uri;
mCastController.setImage(bitmap);
}
if (this == mImageAsyncTask) {
mImageAsyncTask = null;
}
}
};
mImageAsyncTask.execute(uri);
}
Aggregations