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);
}
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);
}
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()));
}
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());
}
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"));
}
}
Aggregations