Search in sources :

Example 36 with Playable

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

Example 37 with Playable

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

the class PlaybackServiceTaskManagerTest method testStartWidgetUpdater.

public void testStartWidgetUpdater() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final int NUM_COUNTDOWNS = 2;
    final int TIMEOUT = 3 * PlaybackServiceTaskManager.WIDGET_UPDATER_NOTIFICATION_INTERVAL;
    final CountDownLatch countDownLatch = new CountDownLatch(NUM_COUNTDOWNS);
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, new PlaybackServiceTaskManager.PSTMCallback() {

        @Override
        public void positionSaverTick() {
        }

        @Override
        public void onSleepTimerAlmostExpired() {
        }

        @Override
        public void onSleepTimerExpired() {
        }

        @Override
        public void onSleepTimerReset() {
        }

        @Override
        public void onWidgetUpdaterTick() {
            countDownLatch.countDown();
        }

        @Override
        public void onChapterLoaded(Playable media) {
        }
    });
    pstm.startWidgetUpdater();
    countDownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
    pstm.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.core.util.playback.Playable) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 38 with Playable

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

the class PlaybackServiceTaskManagerTest method testStartPositionSaver.

public void testStartPositionSaver() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final int NUM_COUNTDOWNS = 2;
    final int TIMEOUT = 3 * PlaybackServiceTaskManager.POSITION_SAVER_WAITING_INTERVAL;
    final CountDownLatch countDownLatch = new CountDownLatch(NUM_COUNTDOWNS);
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, new PlaybackServiceTaskManager.PSTMCallback() {

        @Override
        public void positionSaverTick() {
            countDownLatch.countDown();
        }

        @Override
        public void onSleepTimerAlmostExpired() {
        }

        @Override
        public void onSleepTimerExpired() {
        }

        @Override
        public void onSleepTimerReset() {
        }

        @Override
        public void onWidgetUpdaterTick() {
        }

        @Override
        public void onChapterLoaded(Playable media) {
        }
    });
    pstm.startPositionSaver();
    countDownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
    pstm.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.core.util.playback.Playable) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 39 with Playable

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

the class PlaybackServiceTaskManagerTest method testDisableSleepTimer.

public void testDisableSleepTimer() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final long TIME = 1000;
    final long TIMEOUT = 2 * TIME;
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, new PlaybackServiceTaskManager.PSTMCallback() {

        @Override
        public void positionSaverTick() {
        }

        @Override
        public void onSleepTimerAlmostExpired() {
        }

        @Override
        public void onSleepTimerExpired() {
            fail("Sleeptimer expired");
        }

        @Override
        public void onSleepTimerReset() {
        }

        @Override
        public void onWidgetUpdaterTick() {
        }

        @Override
        public void onChapterLoaded(Playable media) {
        }
    });
    pstm.setSleepTimer(TIME, false, false);
    pstm.disableSleepTimer();
    assertFalse(countDownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));
    pstm.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.core.util.playback.Playable) PlaybackServiceTaskManager(de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 40 with Playable

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

the class TimelineTest method testProcessShownotesAddTimecodeHHMMSSNoChapters.

public void testProcessShownotesAddTimecodeHHMMSSNoChapters() throws Exception {
    final String timeStr = "10:11:12";
    final long time = 3600 * 1000 * 10 + 60 * 1000 * 11 + 12 * 1000;
    Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>");
    Timeline t = new Timeline(context, p);
    String res = t.processShownotes(true);
    checkLinkCorrect(res, new long[] { time }, new String[] { timeStr });
}
Also used : Timeline(de.danoeh.antennapod.core.util.playback.Timeline) Playable(de.danoeh.antennapod.core.util.playback.Playable)

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