Search in sources :

Example 11 with MediaMetadataCompat

use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.

the class MusicProviderTest method testSearchMusicByArtist.

@Test
public void testSearchMusicByArtist() throws Exception {
    int count = 0;
    for (MediaMetadataCompat metadata : provider.searchMusicByArtist("Joe")) {
        String title = metadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST);
        assertTrue(title.contains("Joe"));
        count++;
    }
    assertEquals(3, count);
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) Test(org.junit.Test)

Example 12 with MediaMetadataCompat

use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.

the class MusicProviderTest method testSearchMusicByAlbum.

@Test
public void testSearchMusicByAlbum() throws Exception {
    int count = 0;
    for (MediaMetadataCompat metadata : provider.searchMusicByAlbum("Album")) {
        String title = metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM);
        assertTrue(title.contains("Album"));
        count++;
    }
    assertEquals(5, count);
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) Test(org.junit.Test)

Example 13 with MediaMetadataCompat

use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.

the class PlaybackManagerTest method testPlayFromSearch.

@Test
public void testPlayFromSearch() throws Exception {
    // Using a CountDownLatch, we will check if all callbacks are called correctly when
    // a onPlayFromMediaId command is issued.
    final CountDownLatch latch = new CountDownLatch(5);
    final String expectedMusicId = musicProvider.searchMusicBySongTitle("Music 3").iterator().next().getDescription().getMediaId();
    QueueManager queueManager = new QueueManager(musicProvider, resources, new SimpleMetadataUpdateListener() {

        @Override
        public void onMetadataChanged(MediaMetadataCompat metadata) {
            // Latch countdown 1: QueueManager will change appropriately
            assertEquals(expectedMusicId, metadata.getDescription().getMediaId());
            latch.countDown();
        }
    });
    SimplePlaybackServiceCallback serviceCallback = new SimplePlaybackServiceCallback() {

        @Override
        public void onPlaybackStart() {
            // Latch countdown 2: PlaybackService will get a onPlaybackStart call
            latch.countDown();
        }

        @Override
        public void onPlaybackStateUpdated(PlaybackStateCompat newState) {
            if (newState.getState() == PlaybackStateCompat.STATE_PLAYING) {
                // Latch countdown 3: PlaybackService will get a state updated call (here we
                // ignore the unrelated state changes)
                latch.countDown();
            }
        }

        @Override
        public void onNotificationRequired() {
            // Latch countdown 4: PlaybackService will get call to show a media notification
            latch.countDown();
        }
    };
    Playback playback = new SimplePlayback() {

        @Override
        public void play(MediaSessionCompat.QueueItem item) {
            // Latch countdown 5: Playback will be called with the correct queueItem
            assertEquals(expectedMusicId, MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));
            latch.countDown();
        }
    };
    PlaybackManager playbackManager = new PlaybackManager(serviceCallback, resources, musicProvider, queueManager, playback);
    playbackManager.getMediaSessionCallback().onPlayFromSearch("Music 3", null);
    latch.await(5, TimeUnit.SECONDS);
    // Finally, check if the current music in queueManager is as expected
    assertEquals(expectedMusicId, MediaIDHelper.extractMusicIDFromMediaID(queueManager.getCurrentMusic().getDescription().getMediaId()));
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 14 with MediaMetadataCompat

use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.

the class PlaybackManagerTest method testPlay.

@Test
public void testPlay() throws Exception {
    String mediaId = MediaIDHelper.MEDIA_ID_ROOT;
    while (MediaIDHelper.isBrowseable(mediaId)) {
        mediaId = musicProvider.getChildren(mediaId, resources).get(0).getMediaId();
    }
    // Using a CountDownLatch, we will check if all callbacks are called correctly when
    // a onPlayFromMediaId command is issued.
    final CountDownLatch latch = new CountDownLatch(5);
    final String expectedMediaId = mediaId;
    QueueManager queueManager = new QueueManager(musicProvider, resources, new SimpleMetadataUpdateListener() {

        @Override
        public void onMetadataChanged(MediaMetadataCompat metadata) {
            // Latch countdown 1: QueueManager will change appropriately
            assertEquals(MediaIDHelper.extractMusicIDFromMediaID(expectedMediaId), metadata.getDescription().getMediaId());
            latch.countDown();
        }
    });
    SimplePlaybackServiceCallback serviceCallback = new SimplePlaybackServiceCallback() {

        @Override
        public void onPlaybackStart() {
            // Latch countdown 2: PlaybackService will get a onPlaybackStart call
            latch.countDown();
        }

        @Override
        public void onPlaybackStateUpdated(PlaybackStateCompat newState) {
            if (newState.getState() == PlaybackStateCompat.STATE_PLAYING) {
                // Latch countdown 3: PlaybackService will get a state updated call (here we
                // ignore the unrelated state changes)
                latch.countDown();
            }
        }

        @Override
        public void onNotificationRequired() {
            // Latch countdown 4: PlaybackService will get call to show a media notification
            latch.countDown();
        }
    };
    Playback playback = new SimplePlayback() {

        @Override
        public void play(MediaSessionCompat.QueueItem item) {
            // Latch countdown 5: Playback will be called with the correct queueItem
            assertEquals(expectedMediaId, item.getDescription().getMediaId());
            latch.countDown();
        }
    };
    PlaybackManager playbackManager = new PlaybackManager(serviceCallback, resources, musicProvider, queueManager, playback);
    playbackManager.getMediaSessionCallback().onPlayFromMediaId(expectedMediaId, null);
    latch.await(5, TimeUnit.SECONDS);
    // Finally, check if the current music in queueManager is as expected
    assertEquals(expectedMediaId, queueManager.getCurrentMusic().getDescription().getMediaId());
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 15 with MediaMetadataCompat

use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.

the class QueueHelperTest method testGetPlayingQueueFromUnstructuredSearch.

@Test
public void testGetPlayingQueueFromUnstructuredSearch() throws Exception {
    List<MediaSessionCompat.QueueItem> queue = QueueHelper.getPlayingQueueFromSearch("Romantic", null, provider);
    assertNotNull(queue);
    assertFalse(queue.isEmpty());
    // assert they all contain "Romantic" in the title
    for (MediaSessionCompat.QueueItem item : queue) {
        String musicId = MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId());
        MediaMetadataCompat metadata = provider.getMusic(musicId);
        assertTrue(metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE).contains("Romantic"));
    }
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat) Test(org.junit.Test)

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