Search in sources :

Example 26 with MediaMetadataCompat

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));
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 27 with MediaMetadataCompat

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);
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) Test(org.junit.Test)

Example 28 with MediaMetadataCompat

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());
}
Also used : MediaBrowserCompat(android.support.v4.media.MediaBrowserCompat) MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) MockResources(android.test.mock.MockResources) Test(org.junit.Test)

Example 29 with MediaMetadataCompat

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);
    }
}
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)

Aggregations

MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)29 Test (org.junit.Test)13 MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)8 Bitmap (android.graphics.Bitmap)5 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)4 Uri (android.net.Uri)3 Bundle (android.os.Bundle)3 MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 Intent (android.content.Intent)2 RemoteException (android.os.RemoteException)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 MediaInfo (com.google.android.gms.cast.MediaInfo)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JSONObject (org.json.JSONObject)2 Configuration (android.content.res.Configuration)1