Search in sources :

Example 1 with RemoteMediaClient

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;
}
Also used : MediaQueue(com.google.android.gms.cast.framework.media.MediaQueue) RemoteMediaClient(com.google.android.gms.cast.framework.media.RemoteMediaClient) MediaStatus(com.google.android.gms.cast.MediaStatus)

Example 2 with 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));
}
Also used : RemoteMediaClient(com.google.android.gms.cast.framework.media.RemoteMediaClient) Test(org.junit.Test)

Example 3 with RemoteMediaClient

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();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MediaInfo(com.google.android.gms.cast.MediaInfo) RemoteMediaClient(com.google.android.gms.cast.framework.media.RemoteMediaClient) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException)

Aggregations

RemoteMediaClient (com.google.android.gms.cast.framework.media.RemoteMediaClient)3 MediaInfo (com.google.android.gms.cast.MediaInfo)1 MediaMetadata (com.google.android.gms.cast.MediaMetadata)1 MediaStatus (com.google.android.gms.cast.MediaStatus)1 MediaQueue (com.google.android.gms.cast.framework.media.MediaQueue)1 WebImage (com.google.android.gms.common.images.WebImage)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Test (org.junit.Test)1