use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.
the class MusicProviderTest method testUpdateMusicArt.
@Test
public void testUpdateMusicArt() throws Exception {
Bitmap bIcon = Bitmap.createBitmap(2, 2, Bitmap.Config.ALPHA_8);
Bitmap bArt = Bitmap.createBitmap(2, 2, Bitmap.Config.ALPHA_8);
MediaMetadataCompat metadata = provider.getShuffledMusic().iterator().next();
String musicId = metadata.getDescription().getMediaId();
assertNotEquals(bArt, metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART));
assertNotEquals(bIcon, metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON));
provider.updateMusicArt(musicId, bArt, bIcon);
MediaMetadataCompat newMetadata = provider.getMusic(musicId);
assertEquals(bArt, newMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART));
assertEquals(bIcon, newMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON));
}
use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.
the class MusicProviderTest method testGetMusicsByGenre.
@Test
public void testGetMusicsByGenre() throws Exception {
int count = 0;
for (MediaMetadataCompat metadata : provider.getMusicsByGenre("Genre 1")) {
String genre = metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE);
assertEquals("Genre 1", genre);
count++;
}
assertEquals(3, count);
}
use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.
the class MusicProviderTest method testGetChildren.
@Test
public void testGetChildren() throws Exception {
MockResources resources = new MockResources() {
@NonNull
@Override
public String getString(int id) throws NotFoundException {
return "";
}
@NonNull
@Override
public String getString(int id, Object... formatArgs) throws NotFoundException {
return "";
}
};
// test an invalid root
List<MediaBrowserCompat.MediaItem> invalid = provider.getChildren("INVALID_MEDIA_ID", resources);
assertEquals(0, invalid.size());
// test level 1 (list of category types - only "by genre" for now)
List<MediaBrowserCompat.MediaItem> level1 = provider.getChildren(MediaIDHelper.MEDIA_ID_ROOT, resources);
assertEquals(1, level1.size());
// test level 2 (list of genres)
int genreCount = 0;
for (String ignored : provider.getGenres()) {
genreCount++;
}
List<MediaBrowserCompat.MediaItem> level2 = provider.getChildren(level1.get(0).getMediaId(), resources);
assertEquals(genreCount, level2.size());
// test level 3 (list of music for a given genre)
List<MediaBrowserCompat.MediaItem> level3 = provider.getChildren(level2.get(0).getMediaId(), resources);
String genre = MediaIDHelper.extractBrowseCategoryValueFromMediaID(level2.get(0).getMediaId());
for (MediaBrowserCompat.MediaItem mediaItem : level3) {
assertTrue(mediaItem.isPlayable());
assertFalse(mediaItem.isBrowsable());
MediaMetadataCompat metadata = provider.getMusic(MediaIDHelper.extractMusicIDFromMediaID(mediaItem.getMediaId()));
assertEquals(genre, metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE));
}
// test an invalid level 4
List<MediaBrowserCompat.MediaItem> invalidLevel4 = provider.getChildren(level3.get(0).getMediaId(), resources);
assertTrue(invalidLevel4.isEmpty());
}
use of android.support.v4.media.MediaMetadataCompat 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);
}
}
Aggregations