Search in sources :

Example 11 with PlaybackServiceMediaPlayer

use of de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer 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();
}
Also used : Context(android.content.Context) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer)

Example 12 with PlaybackServiceMediaPlayer

use of de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer 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();
}
Also used : Context(android.content.Context) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) Playable(de.danoeh.antennapod.core.util.playback.Playable) AssertionFailedError(junit.framework.AssertionFailedError)

Example 13 with PlaybackServiceMediaPlayer

use of de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer 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();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.core.util.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

Context (android.content.Context)13 LocalPSMP (de.danoeh.antennapod.core.service.playback.LocalPSMP)13 PlaybackServiceMediaPlayer (de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 AssertionFailedError (junit.framework.AssertionFailedError)12 Playable (de.danoeh.antennapod.core.util.playback.Playable)11