use of de.danoeh.antennapod.core.service.playback.LocalPSMP in project AntennaPod by AntennaPod.
the class PlaybackServiceMediaPlayerTest method testInit.
public void testInit() {
final Context c = getInstrumentation().getTargetContext();
PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, new DefaultPSMPCallback());
psmp.shutdown();
}
use of de.danoeh.antennapod.core.service.playback.LocalPSMP in project AntennaPod by AntennaPod.
the class PlaybackServiceMediaPlayerTest method reinitTestSkeleton.
private void reinitTestSkeleton(final PlayerStatus initialState, final long timeoutSeconds) throws InterruptedException {
final Context c = getInstrumentation().getTargetContext();
final int latchCount = 2;
final CountDownLatch countDownLatch = new CountDownLatch(latchCount);
PlaybackServiceMediaPlayer.PSMPCallback callback = new DefaultPSMPCallback() {
@Override
public void statusChanged(LocalPSMP.PSMPInfo newInfo) {
checkPSMPInfo(newInfo);
if (newInfo.playerStatus == PlayerStatus.ERROR) {
if (assertionError == null)
assertionError = new UnexpectedStateChange(newInfo.playerStatus);
} else {
if (newInfo.playerStatus == initialState) {
countDownLatch.countDown();
} else if (countDownLatch.getCount() < latchCount && newInfo.playerStatus == PlayerStatus.INITIALIZED) {
countDownLatch.countDown();
}
}
}
@Override
public boolean onMediaPlayerError(Object inObj, int what, int extra) {
if (assertionError == null)
assertionError = new AssertionFailedError("Unexpected call to onMediaPlayerError");
return false;
}
};
PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL);
boolean prepareImmediately = initialState != PlayerStatus.INITIALIZED;
boolean startImmediately = initialState != PlayerStatus.PREPARED;
psmp.playMediaObject(p, false, startImmediately, prepareImmediately);
if (initialState == PlayerStatus.PAUSED) {
psmp.pause(false, false);
}
psmp.reinit();
boolean res = countDownLatch.await(timeoutSeconds, TimeUnit.SECONDS);
if (assertionError != null)
throw assertionError;
assertTrue(res);
psmp.shutdown();
}
use of de.danoeh.antennapod.core.service.playback.LocalPSMP in project AntennaPod by AntennaPod.
the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectLocalNoStartNoPrepare.
public void testPlayMediaObjectLocalNoStartNoPrepare() throws InterruptedException {
final Context c = getInstrumentation().getTargetContext();
final CountDownLatch countDownLatch = new CountDownLatch(2);
PlaybackServiceMediaPlayer.PSMPCallback callback = new DefaultPSMPCallback() {
@Override
public void statusChanged(LocalPSMP.PSMPInfo newInfo) {
try {
checkPSMPInfo(newInfo);
if (newInfo.playerStatus == PlayerStatus.ERROR)
throw new IllegalStateException("MediaPlayer error");
if (countDownLatch.getCount() == 0) {
fail();
} else if (countDownLatch.getCount() == 2) {
assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
countDownLatch.countDown();
} else {
assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
countDownLatch.countDown();
}
} catch (AssertionFailedError e) {
if (assertionError == null)
assertionError = e;
}
}
};
PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL);
psmp.playMediaObject(p, false, false, false);
boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
if (assertionError != null)
throw assertionError;
assertTrue(res);
assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.INITIALIZED);
assertFalse(psmp.isStartWhenPrepared());
psmp.shutdown();
}
Aggregations