Media2 tests: Clean up assets
Even after this change, it's unclear to me why we need so many assets for these tests. Just doing a minimal pass for now though! PiperOrigin-RevId: 326613941
This commit is contained in:
parent
602d880841
commit
cdf07f1745
@ -58,7 +58,7 @@ public class MediaSessionUtilTest {
|
|||||||
SessionPlayerConnector sessionPlayerConnector = playerTestRule.getSessionPlayerConnector();
|
SessionPlayerConnector sessionPlayerConnector = playerTestRule.getSessionPlayerConnector();
|
||||||
MediaSession.SessionCallback sessionCallback =
|
MediaSession.SessionCallback sessionCallback =
|
||||||
new SessionCallbackBuilder(context, sessionPlayerConnector).build();
|
new SessionCallbackBuilder(context, sessionPlayerConnector).build();
|
||||||
TestUtils.loadResource(context, R.raw.testmp3_2, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
ListenableFuture<PlayerResult> prepareResult = sessionPlayerConnector.prepare();
|
ListenableFuture<PlayerResult> prepareResult = sessionPlayerConnector.prepare();
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
sessionPlayerConnector.registerPlayerCallback(
|
sessionPlayerConnector.registerPlayerCallback(
|
||||||
|
@ -168,8 +168,8 @@ public class SessionCallbackBuilderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void allowedCommand_whenPlaylistSet_allowsSkipTo() throws Exception {
|
public void allowedCommand_whenPlaylistSet_allowsSkipTo() throws Exception {
|
||||||
List<MediaItem> testPlaylist = new ArrayList<>();
|
List<MediaItem> testPlaylist = new ArrayList<>();
|
||||||
testPlaylist.add(TestUtils.createMediaItem(context, R.raw.testvideo));
|
testPlaylist.add(TestUtils.createMediaItem(context, R.raw.video_desks));
|
||||||
testPlaylist.add(TestUtils.createMediaItem(context, R.raw.sample_not_seekable));
|
testPlaylist.add(TestUtils.createMediaItem(context, R.raw.video_not_seekable));
|
||||||
int testRewindIncrementMs = 100;
|
int testRewindIncrementMs = 100;
|
||||||
int testFastForwardIncrementMs = 100;
|
int testFastForwardIncrementMs = 100;
|
||||||
|
|
||||||
@ -238,9 +238,9 @@ public class SessionCallbackBuilderTest {
|
|||||||
public void allowedCommand_afterCurrentMediaItemPrepared_notifiesSeekToAvailable()
|
public void allowedCommand_afterCurrentMediaItemPrepared_notifiesSeekToAvailable()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
List<MediaItem> testPlaylist = new ArrayList<>();
|
List<MediaItem> testPlaylist = new ArrayList<>();
|
||||||
testPlaylist.add(TestUtils.createMediaItem(context, R.raw.testvideo));
|
testPlaylist.add(TestUtils.createMediaItem(context));
|
||||||
|
|
||||||
int resid = R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
|
int resid = R.raw.video_big_buck_bunny;
|
||||||
TestDataSourceCallback source =
|
TestDataSourceCallback source =
|
||||||
TestDataSourceCallback.fromAssetFd(context.getResources().openRawResourceFd(resid));
|
TestDataSourceCallback.fromAssetFd(context.getResources().openRawResourceFd(resid));
|
||||||
CountDownLatch readAllowedLatch = new CountDownLatch(1);
|
CountDownLatch readAllowedLatch = new CountDownLatch(1);
|
||||||
@ -382,7 +382,7 @@ public class SessionCallbackBuilderTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@Test
|
@Test
|
||||||
public void setRewindIncrementMs_withPositiveRewindIncrement_rewinds() throws Exception {
|
public void setRewindIncrementMs_withPositiveRewindIncrement_rewinds() throws Exception {
|
||||||
int testResId = R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
|
int testResId = R.raw.video_big_buck_bunny;
|
||||||
int testDuration = 10_000;
|
int testDuration = 10_000;
|
||||||
int tolerance = 100;
|
int tolerance = 100;
|
||||||
int testSeekPosition = 2_000;
|
int testSeekPosition = 2_000;
|
||||||
@ -426,7 +426,7 @@ public class SessionCallbackBuilderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void setFastForwardIncrementMs_withPositiveFastForwardIncrement_fastsForward()
|
public void setFastForwardIncrementMs_withPositiveFastForwardIncrement_fastsForward()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
int testResId = R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
|
int testResId = R.raw.video_big_buck_bunny;
|
||||||
int testDuration = 10_000;
|
int testDuration = 10_000;
|
||||||
int tolerance = 100;
|
int tolerance = 100;
|
||||||
int testSeekPosition = 2_000;
|
int testSeekPosition = 2_000;
|
||||||
@ -469,7 +469,7 @@ public class SessionCallbackBuilderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void setMediaItemProvider_withMediaItemProvider_receivesOnCreateMediaItem()
|
public void setMediaItemProvider_withMediaItemProvider_receivesOnCreateMediaItem()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
int testResId = R.raw.testmp3_2;
|
int testResId = R.raw.audio;
|
||||||
Uri testMediaIdUri = TestUtils.createResourceUri(context, testResId);
|
Uri testMediaIdUri = TestUtils.createResourceUri(context, testResId);
|
||||||
|
|
||||||
CountDownLatch providerLatch = new CountDownLatch(1);
|
CountDownLatch providerLatch = new CountDownLatch(1);
|
||||||
|
@ -110,7 +110,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void play_onceWithAudioResource_changesPlayerStateToPlaying() throws Exception {
|
public void play_onceWithAudioResource_changesPlayerStateToPlaying() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3_2, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
|
|
||||||
AudioAttributesCompat attributes =
|
AudioAttributesCompat attributes =
|
||||||
new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
|
new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
|
||||||
@ -144,7 +144,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
.runOnMainSync(
|
.runOnMainSync(
|
||||||
() -> {
|
() -> {
|
||||||
try {
|
try {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3_2, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertWithMessage(e.getMessage()).fail();
|
assertWithMessage(e.getMessage()).fail();
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void setMediaItem_withAudioResource_notifiesOnPlaybackCompleted() throws Exception {
|
public void setMediaItem_withAudioResource_notifiesOnPlaybackCompleted() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
|
|
||||||
CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
|
CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
|
||||||
sessionPlayerConnector.registerPlayerCallback(
|
sessionPlayerConnector.registerPlayerCallback(
|
||||||
@ -235,7 +235,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void setMediaItem_withVideoResource_notifiesOnPlaybackCompleted() throws Exception {
|
public void setMediaItem_withVideoResource_notifiesOnPlaybackCompleted() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testvideo, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.video_desks, sessionPlayerConnector);
|
||||||
CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
|
CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
|
||||||
sessionPlayerConnector.registerPlayerCallback(
|
sessionPlayerConnector.registerPlayerCallback(
|
||||||
executor,
|
executor,
|
||||||
@ -267,18 +267,12 @@ public class SessionPlayerConnectorTest {
|
|||||||
@MediumTest
|
@MediumTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void getDuration_afterPrepared_returnsDuration() throws Exception {
|
public void getDuration_afterPrepared_returnsDuration() throws Exception {
|
||||||
int expectedDuration = 5130;
|
TestUtils.loadResource(context, R.raw.video_desks, sessionPlayerConnector);
|
||||||
int tolerance = 50;
|
|
||||||
|
|
||||||
TestUtils.loadResource(context, R.raw.testvideo, sessionPlayerConnector);
|
|
||||||
|
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
|
|
||||||
assertThat(sessionPlayerConnector.getPlayerState())
|
assertThat(sessionPlayerConnector.getPlayerState())
|
||||||
.isEqualTo(SessionPlayer.PLAYER_STATE_PAUSED);
|
.isEqualTo(SessionPlayer.PLAYER_STATE_PAUSED);
|
||||||
assertThat((float) sessionPlayerConnector.getDuration())
|
assertThat((float) sessionPlayerConnector.getDuration()).isWithin(50).of(5130);
|
||||||
.isWithin(tolerance)
|
|
||||||
.of(expectedDuration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -313,7 +307,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void play_withDataSourceCallback_changesPlayerState() throws Exception {
|
public void play_withDataSourceCallback_changesPlayerState() throws Exception {
|
||||||
int resid = R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
|
int resid = R.raw.video_big_buck_bunny;
|
||||||
|
|
||||||
TestDataSourceCallback dataSource =
|
TestDataSourceCallback dataSource =
|
||||||
TestDataSourceCallback.fromAssetFd(resources.openRawResourceFd(resid));
|
TestDataSourceCallback.fromAssetFd(resources.openRawResourceFd(resid));
|
||||||
@ -346,7 +340,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void setPlaybackSpeed_afterPlayback_remainsSame() throws Exception {
|
public void setPlaybackSpeed_afterPlayback_remainsSame() throws Exception {
|
||||||
int resId1 = R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
|
int resId1 = R.raw.video_big_buck_bunny;
|
||||||
long start1 = 6_000;
|
long start1 = 6_000;
|
||||||
long end1 = 7_000;
|
long end1 = 7_000;
|
||||||
MediaItem mediaItem1 =
|
MediaItem mediaItem1 =
|
||||||
@ -355,7 +349,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
.setEndPosition(end1)
|
.setEndPosition(end1)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
int resId2 = R.raw.testvideo;
|
int resId2 = R.raw.video_desks;
|
||||||
long start2 = 3_000;
|
long start2 = 3_000;
|
||||||
long end2 = 4_000;
|
long end2 = 4_000;
|
||||||
MediaItem mediaItem2 =
|
MediaItem mediaItem2 =
|
||||||
@ -394,7 +388,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void seekTo_withSeriesOfSeek_succeeds() throws Exception {
|
public void seekTo_withSeriesOfSeek_succeeds() throws Exception {
|
||||||
int resid = R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
|
int resid = R.raw.video_big_buck_bunny;
|
||||||
TestUtils.loadResource(context, resid, sessionPlayerConnector);
|
TestUtils.loadResource(context, resid, sessionPlayerConnector);
|
||||||
|
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
@ -410,7 +404,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void seekTo_skipsUnnecessarySeek() throws Exception {
|
public void seekTo_skipsUnnecessarySeek() throws Exception {
|
||||||
int resid = R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
|
int resid = R.raw.video_big_buck_bunny;
|
||||||
TestDataSourceCallback source =
|
TestDataSourceCallback source =
|
||||||
TestDataSourceCallback.fromAssetFd(resources.openRawResourceFd(resid));
|
TestDataSourceCallback.fromAssetFd(resources.openRawResourceFd(resid));
|
||||||
CountDownLatch readAllowedLatch = new CountDownLatch(1);
|
CountDownLatch readAllowedLatch = new CountDownLatch(1);
|
||||||
@ -484,7 +478,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void seekTo_whenUnderlyingPlayerAlsoSeeks_throwsNoException() throws Exception {
|
public void seekTo_whenUnderlyingPlayerAlsoSeeks_throwsNoException() throws Exception {
|
||||||
int resid = R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
|
int resid = R.raw.video_big_buck_bunny;
|
||||||
TestUtils.loadResource(context, resid, sessionPlayerConnector);
|
TestUtils.loadResource(context, resid, sessionPlayerConnector);
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
||||||
@ -506,7 +500,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void seekTo_byUnderlyingPlayer_notifiesOnSeekCompleted() throws Exception {
|
public void seekTo_byUnderlyingPlayer_notifiesOnSeekCompleted() throws Exception {
|
||||||
int resid = R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
|
int resid = R.raw.video_big_buck_bunny;
|
||||||
TestUtils.loadResource(context, resid, sessionPlayerConnector);
|
TestUtils.loadResource(context, resid, sessionPlayerConnector);
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
||||||
@ -536,7 +530,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void getPlayerState_withCallingPrepareAndPlayAndPause_reflectsPlayerState()
|
public void getPlayerState_withCallingPrepareAndPlayAndPause_reflectsPlayerState()
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
TestUtils.loadResource(context, R.raw.testvideo, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.video_desks, sessionPlayerConnector);
|
||||||
assertThat(sessionPlayerConnector.getBufferingState())
|
assertThat(sessionPlayerConnector.getBufferingState())
|
||||||
.isEqualTo(SessionPlayer.BUFFERING_STATE_UNKNOWN);
|
.isEqualTo(SessionPlayer.BUFFERING_STATE_UNKNOWN);
|
||||||
assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(SessionPlayer.PLAYER_STATE_IDLE);
|
assertThat(sessionPlayerConnector.getPlayerState()).isEqualTo(SessionPlayer.PLAYER_STATE_IDLE);
|
||||||
@ -572,7 +566,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void prepare_twice_finishes() throws Exception {
|
public void prepare_twice_finishes() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
assertPlayerResult(sessionPlayerConnector.prepare(), RESULT_INFO_SKIPPED);
|
assertPlayerResult(sessionPlayerConnector.prepare(), RESULT_INFO_SKIPPED);
|
||||||
}
|
}
|
||||||
@ -581,10 +575,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void prepare_notifiesOnPlayerStateChanged() throws Throwable {
|
public void prepare_notifiesOnPlayerStateChanged() throws Throwable {
|
||||||
TestUtils.loadResource(
|
TestUtils.loadResource(context, R.raw.video_big_buck_bunny, sessionPlayerConnector);
|
||||||
context,
|
|
||||||
R.raw.video_480x360_mp4_h264_1000kbps_30fps_aac_stereo_128kbps_44100hz,
|
|
||||||
sessionPlayerConnector);
|
|
||||||
|
|
||||||
CountDownLatch onPlayerStatePaused = new CountDownLatch(1);
|
CountDownLatch onPlayerStatePaused = new CountDownLatch(1);
|
||||||
SessionPlayer.PlayerCallback callback =
|
SessionPlayer.PlayerCallback callback =
|
||||||
@ -606,10 +597,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void prepare_notifiesBufferingCompletedOnce() throws Throwable {
|
public void prepare_notifiesBufferingCompletedOnce() throws Throwable {
|
||||||
TestUtils.loadResource(
|
TestUtils.loadResource(context, R.raw.video_big_buck_bunny, sessionPlayerConnector);
|
||||||
context,
|
|
||||||
R.raw.video_480x360_mp4_h264_1000kbps_30fps_aac_stereo_128kbps_44100hz,
|
|
||||||
sessionPlayerConnector);
|
|
||||||
|
|
||||||
CountDownLatch onBufferingCompletedLatch = new CountDownLatch(2);
|
CountDownLatch onBufferingCompletedLatch = new CountDownLatch(2);
|
||||||
CopyOnWriteArrayList<Integer> bufferingStateChanges = new CopyOnWriteArrayList<>();
|
CopyOnWriteArrayList<Integer> bufferingStateChanges = new CopyOnWriteArrayList<>();
|
||||||
@ -645,10 +633,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void seekTo_whenPrepared_notifiesOnSeekCompleted() throws Throwable {
|
public void seekTo_whenPrepared_notifiesOnSeekCompleted() throws Throwable {
|
||||||
long mp4DurationMs = 8_484L;
|
long mp4DurationMs = 8_484L;
|
||||||
TestUtils.loadResource(
|
TestUtils.loadResource(context, R.raw.video_big_buck_bunny, sessionPlayerConnector);
|
||||||
context,
|
|
||||||
R.raw.video_480x360_mp4_h264_1000kbps_30fps_aac_stereo_128kbps_44100hz,
|
|
||||||
sessionPlayerConnector);
|
|
||||||
|
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
|
|
||||||
@ -671,10 +656,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void setPlaybackSpeed_whenPrepared_notifiesOnPlaybackSpeedChanged() throws Throwable {
|
public void setPlaybackSpeed_whenPrepared_notifiesOnPlaybackSpeedChanged() throws Throwable {
|
||||||
TestUtils.loadResource(
|
TestUtils.loadResource(context, R.raw.video_big_buck_bunny, sessionPlayerConnector);
|
||||||
context,
|
|
||||||
R.raw.video_480x360_mp4_h264_1000kbps_30fps_aac_stereo_128kbps_44100hz,
|
|
||||||
sessionPlayerConnector);
|
|
||||||
|
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
|
|
||||||
@ -723,7 +705,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void close_throwsNoExceptionAndDoesNotCrash() throws Exception {
|
public void close_throwsNoExceptionAndDoesNotCrash() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3_2, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
AudioAttributesCompat attributes =
|
AudioAttributesCompat attributes =
|
||||||
new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
|
new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
|
||||||
sessionPlayerConnector.setAudioAttributes(attributes);
|
sessionPlayerConnector.setAudioAttributes(attributes);
|
||||||
@ -748,7 +730,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
DataSourceCallback dataSource =
|
DataSourceCallback dataSource =
|
||||||
new DataSourceCallback() {
|
new DataSourceCallback() {
|
||||||
TestDataSourceCallback testSource =
|
TestDataSourceCallback testSource =
|
||||||
TestDataSourceCallback.fromAssetFd(resources.openRawResourceFd(R.raw.testmp3));
|
TestDataSourceCallback.fromAssetFd(resources.openRawResourceFd(R.raw.audio));
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int readAt(long position, byte[] buffer, int offset, int size) throws IOException {
|
public int readAt(long position, byte[] buffer, int offset, int size) throws IOException {
|
||||||
@ -971,7 +953,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void play_twice_finishes() throws Exception {
|
public void play_twice_finishes() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.play());
|
assertPlayerResultSuccess(sessionPlayerConnector.play());
|
||||||
assertPlayerResult(sessionPlayerConnector.play(), RESULT_INFO_SKIPPED);
|
assertPlayerResult(sessionPlayerConnector.play(), RESULT_INFO_SKIPPED);
|
||||||
@ -983,9 +965,9 @@ public class SessionPlayerConnectorTest {
|
|||||||
public void play_withPlaylist_notifiesOnCurrentMediaItemChangedAndOnPlaybackCompleted()
|
public void play_withPlaylist_notifiesOnCurrentMediaItemChangedAndOnPlaybackCompleted()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
List<MediaItem> playlist = new ArrayList<>();
|
List<MediaItem> playlist = new ArrayList<>();
|
||||||
playlist.add(TestUtils.createMediaItem(context, R.raw.number1));
|
playlist.add(TestUtils.createMediaItem(context, R.raw.video_1));
|
||||||
playlist.add(TestUtils.createMediaItem(context, R.raw.number2));
|
playlist.add(TestUtils.createMediaItem(context, R.raw.video_2));
|
||||||
playlist.add(TestUtils.createMediaItem(context, R.raw.number3));
|
playlist.add(TestUtils.createMediaItem(context, R.raw.video_3));
|
||||||
|
|
||||||
CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
|
CountDownLatch onPlaybackCompletedLatch = new CountDownLatch(1);
|
||||||
sessionPlayerConnector.registerPlayerCallback(
|
sessionPlayerConnector.registerPlayerCallback(
|
||||||
@ -1022,7 +1004,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void play_byUnderlyingPlayer_notifiesOnPlayerStateChanges() throws Exception {
|
public void play_byUnderlyingPlayer_notifiesOnPlayerStateChanges() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3_2, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
||||||
|
|
||||||
CountDownLatch onPlayingLatch = new CountDownLatch(1);
|
CountDownLatch onPlayingLatch = new CountDownLatch(1);
|
||||||
@ -1048,7 +1030,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void pause_twice_finishes() throws Exception {
|
public void pause_twice_finishes() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.play());
|
assertPlayerResultSuccess(sessionPlayerConnector.play());
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.pause());
|
assertPlayerResultSuccess(sessionPlayerConnector.pause());
|
||||||
@ -1059,7 +1041,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void pause_byUnderlyingPlayer_notifiesOnPlayerStateChanges() throws Exception {
|
public void pause_byUnderlyingPlayer_notifiesOnPlayerStateChanges() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3_2, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
||||||
|
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
@ -1086,7 +1068,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.KITKAT)
|
||||||
public void pause_byUnderlyingPlayerInListener_changesToPlayerStatePaused() throws Exception {
|
public void pause_byUnderlyingPlayerInListener_changesToPlayerStatePaused() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3_2, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
SimpleExoPlayer simpleExoPlayer = playerTestRule.getSimpleExoPlayer();
|
||||||
|
|
||||||
CountDownLatch playerStateChangesLatch = new CountDownLatch(3);
|
CountDownLatch playerStateChangesLatch = new CountDownLatch(3);
|
||||||
@ -1133,9 +1115,9 @@ public class SessionPlayerConnectorTest {
|
|||||||
public void skipToNextAndPrevious_calledInARow_notifiesOnCurrentMediaItemChanged()
|
public void skipToNextAndPrevious_calledInARow_notifiesOnCurrentMediaItemChanged()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
List<MediaItem> playlist = new ArrayList<>();
|
List<MediaItem> playlist = new ArrayList<>();
|
||||||
playlist.add(TestUtils.createMediaItem(context, R.raw.number1));
|
playlist.add(TestUtils.createMediaItem(context, R.raw.video_1));
|
||||||
playlist.add(TestUtils.createMediaItem(context, R.raw.number2));
|
playlist.add(TestUtils.createMediaItem(context, R.raw.video_2));
|
||||||
playlist.add(TestUtils.createMediaItem(context, R.raw.number3));
|
playlist.add(TestUtils.createMediaItem(context, R.raw.video_3));
|
||||||
assertThat(sessionPlayerConnector.setPlaylist(playlist, /* metadata= */ null)).isNotNull();
|
assertThat(sessionPlayerConnector.setPlaylist(playlist, /* metadata= */ null)).isNotNull();
|
||||||
|
|
||||||
// STEP 1: prepare()
|
// STEP 1: prepare()
|
||||||
@ -1189,9 +1171,9 @@ public class SessionPlayerConnectorTest {
|
|||||||
public void setRepeatMode_withRepeatAll_continuesToPlayPlaylistWithoutBeingCompleted()
|
public void setRepeatMode_withRepeatAll_continuesToPlayPlaylistWithoutBeingCompleted()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
List<MediaItem> playlist = new ArrayList<>();
|
List<MediaItem> playlist = new ArrayList<>();
|
||||||
playlist.add(TestUtils.createMediaItem(context, R.raw.number1));
|
playlist.add(TestUtils.createMediaItem(context, R.raw.video_1));
|
||||||
playlist.add(TestUtils.createMediaItem(context, R.raw.number2));
|
playlist.add(TestUtils.createMediaItem(context, R.raw.video_2));
|
||||||
playlist.add(TestUtils.createMediaItem(context, R.raw.number3));
|
playlist.add(TestUtils.createMediaItem(context, R.raw.video_3));
|
||||||
int listSize = playlist.size();
|
int listSize = playlist.size();
|
||||||
|
|
||||||
// Any value more than list size + 1, to see repeat mode with the recorded video.
|
// Any value more than list size + 1, to see repeat mode with the recorded video.
|
||||||
@ -1244,7 +1226,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
@Test
|
@Test
|
||||||
@LargeTest
|
@LargeTest
|
||||||
public void getPlayerState_withPrepareAndPlayAndPause_changesAsExpected() throws Exception {
|
public void getPlayerState_withPrepareAndPlayAndPause_changesAsExpected() throws Exception {
|
||||||
TestUtils.loadResource(context, R.raw.testmp3, sessionPlayerConnector);
|
TestUtils.loadResource(context, R.raw.audio, sessionPlayerConnector);
|
||||||
|
|
||||||
AudioAttributesCompat attributes =
|
AudioAttributesCompat attributes =
|
||||||
new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
|
new AudioAttributesCompat.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build();
|
||||||
|
@ -29,12 +29,14 @@ import androidx.media2.common.MediaMetadata;
|
|||||||
import androidx.media2.common.SessionPlayer;
|
import androidx.media2.common.SessionPlayer;
|
||||||
import androidx.media2.common.SessionPlayer.PlayerResult;
|
import androidx.media2.common.SessionPlayer.PlayerResult;
|
||||||
import androidx.media2.common.UriMediaItem;
|
import androidx.media2.common.UriMediaItem;
|
||||||
|
import com.google.android.exoplayer2.ext.media2.test.R;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
/** Utilities for tests. */
|
/** Utilities for tests. */
|
||||||
public final class TestUtils {
|
/* package */ final class TestUtils {
|
||||||
|
|
||||||
private static final long PLAYER_STATE_CHANGE_WAIT_TIME_MS = 5_000;
|
private static final long PLAYER_STATE_CHANGE_WAIT_TIME_MS = 5_000;
|
||||||
|
|
||||||
public static Uri createResourceUri(Context context, int resId) {
|
public static Uri createResourceUri(Context context, int resId) {
|
||||||
@ -48,17 +50,17 @@ public final class TestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static MediaItem createMediaItem(Context context) {
|
public static MediaItem createMediaItem(Context context) {
|
||||||
return createMediaItem(context, com.google.android.exoplayer2.ext.media2.test.R.raw.testvideo);
|
return createMediaItem(context, R.raw.video_desks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MediaItem createMediaItem(Context context, int resId) {
|
public static MediaItem createMediaItem(Context context, int resId) {
|
||||||
Uri testVideoUri = createResourceUri(context, resId);
|
Uri resourceUri = createResourceUri(context, resId);
|
||||||
String resourceName = context.getResources().getResourceName(resId);
|
String resourceName = context.getResources().getResourceName(resId);
|
||||||
MediaMetadata metadata =
|
MediaMetadata metadata =
|
||||||
new MediaMetadata.Builder()
|
new MediaMetadata.Builder()
|
||||||
.putString(MediaMetadata.METADATA_KEY_MEDIA_ID, resourceName)
|
.putString(MediaMetadata.METADATA_KEY_MEDIA_ID, resourceName)
|
||||||
.build();
|
.build();
|
||||||
return new UriMediaItem.Builder(testVideoUri).setMetadata(metadata).build();
|
return new UriMediaItem.Builder(resourceUri).setMetadata(metadata).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MediaItem> createPlaylist(Context context, int size) {
|
public static List<MediaItem> createPlaylist(Context context, int size) {
|
||||||
@ -71,7 +73,6 @@ public final class TestUtils {
|
|||||||
|
|
||||||
public static void loadResource(Context context, int resId, SessionPlayer sessionPlayer)
|
public static void loadResource(Context context, int resId, SessionPlayer sessionPlayer)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Uri testUri = TestUtils.createResourceUri(context, resId);
|
|
||||||
MediaItem mediaItem = createMediaItem(context, resId);
|
MediaItem mediaItem = createMediaItem(context, resId);
|
||||||
assertPlayerResultSuccess(sessionPlayer.setMediaItem(mediaItem));
|
assertPlayerResultSuccess(sessionPlayer.setMediaItem(mediaItem));
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user