diff --git a/srgmediaplayer/src/androidTest/java/ch/srg/mediaplayer/PlaybackTest.java b/srgmediaplayer/src/androidTest/java/ch/srg/mediaplayer/PlaybackTest.java index be3045b..efa861b 100644 --- a/srgmediaplayer/src/androidTest/java/ch/srg/mediaplayer/PlaybackTest.java +++ b/srgmediaplayer/src/androidTest/java/ch/srg/mediaplayer/PlaybackTest.java @@ -13,8 +13,11 @@ import org.junit.Test; import org.junit.runner.RunWith; +import java.util.Arrays; +import java.util.List; import java.util.Random; +import ch.srg.mediaplayer.segment.model.Segment; import ch.srg.mediaplayer.utils.SRGMediaPlayerControllerQueueListener; /** @@ -226,7 +229,7 @@ public void testOnDemandAudioPlaythrough() throws Exception { } @Test - public void testPlayAtPosition() throws Exception { + public void testPlayAndSeekToPosition() throws Exception { controller.play(AUDIO_ON_DEMAND_URI, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE); waitForState(SRGMediaPlayerController.State.READY); controller.seekTo((long) 30000); @@ -235,6 +238,39 @@ public void testPlayAtPosition() throws Exception { assertEquals(30, controller.getMediaPosition() / 1000); } + @Test + public void testPlayAtStartingPosition() throws Exception { + Long position = 3000L; + controller.play(AUDIO_ON_DEMAND_URI, position, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE); + waitForState(SRGMediaPlayerController.State.READY); + assertTrue(controller.isPlaying()); + assertEquals(3, controller.getMediaPosition() / 1000); + } + + @Test + public void testPlayAtStartingPositionNull() throws Exception { + Long position = null; + controller.play(AUDIO_ON_DEMAND_URI, position, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE); + waitForState(SRGMediaPlayerController.State.READY); + assertTrue(controller.isPlaying()); + assertEquals(0, controller.getMediaPosition() / 1000); + } + + @Test + public void testPlayAtStartingPositionWitSegment() throws Exception { + Segment segment0 = new Segment("segmentId0", "Segment0", null, null, null, + 3000L, 10000L, 7000L, 0L, true, false, false); + Segment segment1 = new Segment("segmentId1", "Segment1", null, null, null, + 12000L, 15000L, 3000L, 0L, true, false, false); + List listSegment = Arrays.asList(segment0, segment1); + + controller.prepare(AUDIO_ON_DEMAND_URI, 0L, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE, listSegment, segment1); + controller.start(); + waitForState(SRGMediaPlayerController.State.READY); + assertTrue(controller.isPlaying()); + assertEquals(12, controller.getMediaPosition() / 1000); + } + @Test public void testPlayAfterStreamEnd() throws Exception { controller.play(AUDIO_ON_DEMAND_URI, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE); @@ -263,7 +299,7 @@ public void testSeek() throws Exception { controller.seekTo(60 * 1000); waitForState(SRGMediaPlayerController.State.BUFFERING); waitForState(SRGMediaPlayerController.State.READY); - assertEquals(60,controller.getMediaPosition() / 1000); + assertEquals(60, controller.getMediaPosition() / 1000); assertTrue(controller.isPlaying()); } @@ -307,7 +343,7 @@ public void testSeekWhilePreparing() throws Exception { controller.seekTo(60 * 1000); assertTrue(controller.isLoading() || controller.isPlaying()); waitForState(SRGMediaPlayerController.State.READY); - assertEquals(60,controller.getMediaPosition() / 1000); + assertEquals(60, controller.getMediaPosition() / 1000); while (!controller.isPlaying()) { Thread.sleep(100); } @@ -333,13 +369,13 @@ public void testSeekWhilePaused() throws Exception { controller.pause(); Thread.sleep(100); // Need to wait assertFalse(controller.isPlaying()); - assertEquals(0,controller.getMediaPosition() / 1000); + assertEquals(0, controller.getMediaPosition() / 1000); controller.seekTo(60 * 1000); // TODO: No BUFFERING? waitForState(SRGMediaPlayerController.State.READY); waitForEvent(SRGMediaPlayerController.Event.Type.DID_SEEK); - assertEquals(60,controller.getMediaPosition() / 1000); + assertEquals(60, controller.getMediaPosition() / 1000); assertFalse(controller.isPlaying()); } @@ -353,13 +389,13 @@ public void testPauseStartPositionKept() throws Exception { controller.pause(); Thread.sleep(100); // Need to wait assertFalse(controller.isPlaying()); - assertEquals(60,controller.getMediaPosition() / 1000); + assertEquals(60, controller.getMediaPosition() / 1000); controller.start(); waitForState(SRGMediaPlayerController.State.READY); waitForEvent(SRGMediaPlayerController.Event.Type.PLAYING_STATE_CHANGE); - assertEquals(60,controller.getMediaPosition() / 1000); + assertEquals(60, controller.getMediaPosition() / 1000); assertTrue(controller.isPlaying()); } diff --git a/srgmediaplayer/src/main/java/ch/srg/mediaplayer/SRGMediaPlayerController.java b/srgmediaplayer/src/main/java/ch/srg/mediaplayer/SRGMediaPlayerController.java index c386213..80cf561 100644 --- a/srgmediaplayer/src/main/java/ch/srg/mediaplayer/SRGMediaPlayerController.java +++ b/srgmediaplayer/src/main/java/ch/srg/mediaplayer/SRGMediaPlayerController.java @@ -460,7 +460,6 @@ public interface Listener { @Nullable private AkamaiMediaAnalyticsConfiguration akamaiMediaAnalyticsConfiguration; - // FIXME : why userAgent letterbox is set here? private static final String userAgent = "curl/Letterbox_2.0"; // temporarily using curl/ user agent to force subtitles with Akamai beta @Nullable private DrmConfig drmConfig;