use of com.google.android.gms.cast.framework.media.RemoteMediaClient in project ExoPlayer by google.
the class CastTimelineTrackerTest method mockRemoteMediaClient.
private static RemoteMediaClient mockRemoteMediaClient(int[] itemIds, int currentItemId, long currentDurationMs) {
RemoteMediaClient remoteMediaClient = Mockito.mock(RemoteMediaClient.class);
MediaStatus status = Mockito.mock(MediaStatus.class);
when(status.getQueueItems()).thenReturn(Collections.emptyList());
when(remoteMediaClient.getMediaStatus()).thenReturn(status);
when(status.getMediaInfo()).thenReturn(getMediaInfo(currentDurationMs));
when(status.getCurrentItemId()).thenReturn(currentItemId);
MediaQueue mediaQueue = mockMediaQueue(itemIds);
when(remoteMediaClient.getMediaQueue()).thenReturn(mediaQueue);
return remoteMediaClient;
}
use of com.google.android.gms.cast.framework.media.RemoteMediaClient in project ExoPlayer by google.
the class CastTimelineTrackerTest method getCastTimelinePersistsDuration.
/**
* Tests that duration of the current media info is correctly propagated to the timeline.
*/
@Test
public void getCastTimelinePersistsDuration() {
CastTimelineTracker tracker = new CastTimelineTracker();
RemoteMediaClient remoteMediaClient = mockRemoteMediaClient(/* itemIds= */
new int[] { 1, 2, 3, 4, 5 }, /* currentItemId= */
2, /* currentDurationMs= */
DURATION_2_MS);
TimelineAsserts.assertPeriodDurations(tracker.getCastTimeline(remoteMediaClient), C.TIME_UNSET, Util.msToUs(DURATION_2_MS), C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET);
remoteMediaClient = mockRemoteMediaClient(/* itemIds= */
new int[] { 1, 2, 3 }, /* currentItemId= */
3, /* currentDurationMs= */
DURATION_3_MS);
TimelineAsserts.assertPeriodDurations(tracker.getCastTimeline(remoteMediaClient), C.TIME_UNSET, Util.msToUs(DURATION_2_MS), Util.msToUs(DURATION_3_MS));
remoteMediaClient = mockRemoteMediaClient(/* itemIds= */
new int[] { 1, 3 }, /* currentItemId= */
3, /* currentDurationMs= */
DURATION_3_MS);
TimelineAsserts.assertPeriodDurations(tracker.getCastTimeline(remoteMediaClient), C.TIME_UNSET, Util.msToUs(DURATION_3_MS));
remoteMediaClient = mockRemoteMediaClient(/* itemIds= */
new int[] { 1, 2, 3, 4, 5 }, /* currentItemId= */
4, /* currentDurationMs= */
DURATION_4_MS);
TimelineAsserts.assertPeriodDurations(tracker.getCastTimeline(remoteMediaClient), C.TIME_UNSET, C.TIME_UNSET, Util.msToUs(DURATION_3_MS), Util.msToUs(DURATION_4_MS), C.TIME_UNSET);
remoteMediaClient = mockRemoteMediaClient(/* itemIds= */
new int[] { 1, 2, 3, 4, 5 }, /* currentItemId= */
5, /* currentDurationMs= */
DURATION_5_MS);
TimelineAsserts.assertPeriodDurations(tracker.getCastTimeline(remoteMediaClient), C.TIME_UNSET, C.TIME_UNSET, Util.msToUs(DURATION_3_MS), Util.msToUs(DURATION_4_MS), Util.msToUs(DURATION_5_MS));
}
use of com.google.android.gms.cast.framework.media.RemoteMediaClient in project Timber by naman14.
the class TimberCastHelper method startCasting.
public static void startCasting(CastSession castSession, Song song) {
String ipAddress = TimberUtils.getIPAddress(true);
URL baseUrl;
try {
baseUrl = new URL("http", ipAddress, Constants.CAST_SERVER_PORT, "");
} catch (MalformedURLException e) {
e.printStackTrace();
return;
}
String songUrl = baseUrl.toString() + "/song?id=" + song.id;
String albumArtUrl = baseUrl.toString() + "/albumart?id=" + song.albumId;
MediaMetadata musicMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
musicMetadata.putString(MediaMetadata.KEY_TITLE, song.title);
musicMetadata.putString(MediaMetadata.KEY_ARTIST, song.artistName);
musicMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, song.albumName);
musicMetadata.putInt(MediaMetadata.KEY_TRACK_NUMBER, song.trackNumber);
musicMetadata.addImage(new WebImage(Uri.parse(albumArtUrl)));
try {
MediaInfo mediaInfo = new MediaInfo.Builder(songUrl).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setContentType("audio/mpeg").setMetadata(musicMetadata).setStreamDuration(song.duration).build();
RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient();
remoteMediaClient.load(mediaInfo, true, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations