Search in sources :

Example 16 with Playable

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

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectStreamStartPrepare.

@Test
@UiThreadTest
public void testPlayMediaObjectStreamStartPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(5);
    CancelablePSMPCallback callback = new CancelablePSMPCallback(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() == 5) {
                    assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 4) {
                    assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 3) {
                    assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 2) {
                    assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 1) {
                    assertEquals(PlayerStatus.PLAYING, newInfo.playerStatus);
                }
                countDownLatch.countDown();
            } catch (AssertionFailedError e) {
                if (assertionError == null)
                    assertionError = e;
            }
        }
    });
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
    Playable p = writeTestPlayable(playableFileUrl, null);
    psmp.playMediaObject(p, true, true, true);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertSame(PlayerStatus.PLAYING, psmp.getPSMPInfo().playerStatus);
    callback.cancel();
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.model.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 17 with Playable

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

the class AudioPlayerFragment method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem item) {
    if (controller == null) {
        return false;
    }
    Playable media = controller.getMedia();
    if (media == null) {
        return false;
    }
    @Nullable final FeedItem feedItem = (media instanceof FeedMedia) ? ((FeedMedia) media).getItem() : null;
    if (feedItem != null && FeedItemMenuHandler.onMenuItemClicked(this, item.getItemId(), feedItem)) {
        return true;
    }
    final int itemId = item.getItemId();
    if (itemId == R.id.disable_sleeptimer_item || itemId == R.id.set_sleeptimer_item) {
        new SleepTimerDialog().show(getChildFragmentManager(), "SleepTimerDialog");
        return true;
    } else if (itemId == R.id.audio_controls) {
        PlaybackControlsDialog dialog = PlaybackControlsDialog.newInstance();
        dialog.show(getChildFragmentManager(), "playback_controls");
        return true;
    } else if (itemId == R.id.open_feed_item) {
        if (feedItem != null) {
            Intent intent = MainActivity.getIntentToOpenFeed(getContext(), feedItem.getFeedId());
            startActivity(intent);
        }
        return true;
    }
    return false;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Playable(de.danoeh.antennapod.model.playback.Playable) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) PlaybackControlsDialog(de.danoeh.antennapod.dialog.PlaybackControlsDialog) SleepTimerDialog(de.danoeh.antennapod.dialog.SleepTimerDialog) Intent(android.content.Intent) Nullable(androidx.annotation.Nullable)

Example 18 with Playable

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

the class ItemDescriptionFragment method load.

private void load() {
    Log.d(TAG, "load()");
    if (webViewLoader != null) {
        webViewLoader.dispose();
    }
    webViewLoader = Maybe.<String>create(emitter -> {
        Playable media = controller.getMedia();
        if (media == null) {
            emitter.onComplete();
            return;
        }
        if (media instanceof FeedMedia) {
            FeedMedia feedMedia = ((FeedMedia) media);
            if (feedMedia.getItem() == null) {
                feedMedia.setItem(DBReader.getFeedItem(feedMedia.getItemId()));
            }
            DBReader.loadDescriptionOfFeedItem(feedMedia.getItem());
        }
        Timeline timeline = new Timeline(getActivity(), media.getDescription(), media.getDuration());
        emitter.onSuccess(timeline.processShownotes());
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(data -> {
        webvDescription.loadDataWithBaseURL("https://127.0.0.1", data, "text/html", "utf-8", "about:blank");
        Log.d(TAG, "Webview loaded");
    }, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
Also used : PlaybackController(de.danoeh.antennapod.core.util.playback.PlaybackController) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) Maybe(io.reactivex.Maybe) Playable(de.danoeh.antennapod.model.playback.Playable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) Timeline(de.danoeh.antennapod.core.util.playback.Timeline) Disposable(io.reactivex.disposables.Disposable) SharedPreferences(android.content.SharedPreferences) ShownotesWebView(de.danoeh.antennapod.view.ShownotesWebView) Fragment(androidx.fragment.app.Fragment) DBReader(de.danoeh.antennapod.core.storage.DBReader) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) Activity(android.app.Activity) Log(android.util.Log) Timeline(de.danoeh.antennapod.core.util.playback.Timeline) Playable(de.danoeh.antennapod.model.playback.Playable) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 19 with Playable

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

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectLocalNoStartPrepare.

@Test
@UiThreadTest
public void testPlayMediaObjectLocalNoStartPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(4);
    CancelablePSMPCallback callback = new CancelablePSMPCallback(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(playableFileUrl, 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);
    assertSame(PlayerStatus.PREPARED, psmp.getPSMPInfo().playerStatus);
    callback.cancel();
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.model.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 20 with Playable

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

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectLocalStartNoPrepare.

@Test
@UiThreadTest
public void testPlayMediaObjectLocalStartNoPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    CancelablePSMPCallback callback = new CancelablePSMPCallback(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(playableFileUrl, PLAYABLE_LOCAL_URL);
    psmp.playMediaObject(p, false, true, false);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertSame(PlayerStatus.INITIALIZED, psmp.getPSMPInfo().playerStatus);
    assertTrue(psmp.isStartWhenPrepared());
    callback.cancel();
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.model.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

Playable (de.danoeh.antennapod.model.playback.Playable)35 Context (android.content.Context)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 LocalPSMP (de.danoeh.antennapod.core.service.playback.LocalPSMP)11 PlaybackServiceMediaPlayer (de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer)11 Test (org.junit.Test)11 UiThreadTest (androidx.test.annotation.UiThreadTest)10 AssertionFailedError (junit.framework.AssertionFailedError)9 MediumTest (androidx.test.filters.MediumTest)8 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)8 LayoutInflater (android.view.LayoutInflater)3 Nullable (androidx.annotation.Nullable)3 PlayerErrorEvent (de.danoeh.antennapod.event.PlayerErrorEvent)3 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)3 FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 Log (android.util.Log)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2