Search in sources :

Example 31 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method pauseTestSkeleton.

private void pauseTestSkeleton(final PlayerStatus initialState, final boolean stream, final boolean abandonAudioFocus, final boolean reinit, long timeoutSeconds) throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final int latchCount = (stream && reinit) ? 2 : 1;
    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 (initialState != PlayerStatus.PLAYING) {
                if (assertionError == null)
                    assertionError = new UnexpectedStateChange(newInfo.playerStatus);
            } else {
                switch(newInfo.playerStatus) {
                    case PAUSED:
                        if (latchCount == countDownLatch.getCount())
                            countDownLatch.countDown();
                        else {
                            if (assertionError == null)
                                assertionError = new UnexpectedStateChange(newInfo.playerStatus);
                        }
                        break;
                    case INITIALIZED:
                        if (stream && reinit && countDownLatch.getCount() < latchCount) {
                            countDownLatch.countDown();
                        } else if (countDownLatch.getCount() < latchCount) {
                            if (assertionError == null)
                                assertionError = new UnexpectedStateChange(newInfo.playerStatus);
                        }
                        break;
                }
            }
        }

        @Override
        public void shouldStop() {
            if (assertionError == null)
                assertionError = new AssertionFailedError("Unexpected call to shouldStop");
        }

        @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);
    if (initialState == PlayerStatus.PLAYING) {
        psmp.playMediaObject(p, stream, true, true);
    }
    psmp.pause(abandonAudioFocus, reinit);
    boolean res = countDownLatch.await(timeoutSeconds, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res || initialState != PlayerStatus.PLAYING);
    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 32 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectStreamStartNoPrepare.

public void testPlayMediaObjectStreamStartNoPrepare() 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, null);
    psmp.playMediaObject(p, true, true, false);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.INITIALIZED);
    assertTrue(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)

Example 33 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectLocalNoStartPrepare.

public void testPlayMediaObjectLocalNoStartPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(4);
    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() == 4) {
                    assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 3) {
                    assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 2) {
                    assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 1) {
                    assertEquals(PlayerStatus.PREPARED, 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, true);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.PREPARED);
    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)

Example 34 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method prepareTestSkeleton.

private void prepareTestSkeleton(final PlayerStatus initialState, long timeoutSeconds) throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final int latchCount = 1;
    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 (initialState == PlayerStatus.INITIALIZED && newInfo.playerStatus == PlayerStatus.PREPARED) {
                    countDownLatch.countDown();
                } else if (initialState != PlayerStatus.INITIALIZED && initialState == newInfo.playerStatus) {
                    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);
    if (initialState == PlayerStatus.INITIALIZED || initialState == PlayerStatus.PLAYING || initialState == PlayerStatus.PREPARED || initialState == PlayerStatus.PAUSED) {
        boolean prepareImmediately = (initialState != PlayerStatus.INITIALIZED);
        boolean startWhenPrepared = (initialState != PlayerStatus.PREPARED);
        psmp.playMediaObject(p, false, startWhenPrepared, prepareImmediately);
        if (initialState == PlayerStatus.PAUSED) {
            psmp.pause(false, false);
        }
        psmp.prepare();
    }
    boolean res = countDownLatch.await(timeoutSeconds, TimeUnit.SECONDS);
    if (initialState != PlayerStatus.INITIALIZED) {
        assertEquals(initialState, psmp.getPSMPInfo().playerStatus);
    }
    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 35 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable 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)

Aggregations

Playable (de.danoeh.antennapod.core.util.playback.Playable)40 Context (android.content.Context)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 LocalPSMP (de.danoeh.antennapod.core.service.playback.LocalPSMP)11 PlaybackServiceMediaPlayer (de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer)11 AssertionFailedError (junit.framework.AssertionFailedError)11 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)8 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)7 Intent (android.content.Intent)4 PlaybackServiceTaskManager (de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager)4 Timeline (de.danoeh.antennapod.core.util.playback.Timeline)4 SharedPreferences (android.content.SharedPreferences)3 TypedArray (android.content.res.TypedArray)3 IconDrawable (com.joanzapata.iconify.IconDrawable)3 TargetApi (android.annotation.TargetApi)2 Color (android.graphics.Color)2 PixelFormat (android.graphics.PixelFormat)2 Uri (android.net.Uri)2 Build (android.os.Build)2 Bundle (android.os.Bundle)2