Search in sources :

Example 11 with Playable

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

the class ChaptersFragment method loadMediaInfo.

private void loadMediaInfo() {
    if (disposable != null) {
        disposable.dispose();
    }
    disposable = Maybe.create(emitter -> {
        Playable media = controller.getMedia();
        if (media != null) {
            ChapterUtils.loadChapters(media, getContext());
            emitter.onSuccess(media);
        } else {
            emitter.onComplete();
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(media -> onMediaChanged((Playable) media), error -> Log.e(TAG, Log.getStackTraceString(error)));
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) PlaybackController(de.danoeh.antennapod.core.util.playback.PlaybackController) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) Maybe(io.reactivex.Maybe) Dialog(android.app.Dialog) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) AppCompatDialogFragment(androidx.appcompat.app.AppCompatDialogFragment) EventBus(org.greenrobot.eventbus.EventBus) PlaybackPositionEvent(de.danoeh.antennapod.event.playback.PlaybackPositionEvent) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) RecyclerView(androidx.recyclerview.widget.RecyclerView) ChaptersListAdapter(de.danoeh.antennapod.adapter.ChaptersListAdapter) Chapter(de.danoeh.antennapod.model.feed.Chapter) Log(android.util.Log) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) Playable(de.danoeh.antennapod.model.playback.Playable) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) PlayerStatus(de.danoeh.antennapod.playback.base.PlayerStatus) Disposable(io.reactivex.disposables.Disposable) Nullable(androidx.annotation.Nullable) Subscribe(org.greenrobot.eventbus.Subscribe) ChapterUtils(de.danoeh.antennapod.core.util.ChapterUtils) RelativeLayout(android.widget.RelativeLayout) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Playable(de.danoeh.antennapod.model.playback.Playable)

Example 12 with Playable

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

the class VideoplayerActivity method setupView.

protected void setupView() {
    showTimeLeft = UserPreferences.shouldShowRemainingTime();
    Log.d("timeleft", showTimeLeft ? "true" : "false");
    viewBinding.durationLabel.setOnClickListener(v -> {
        showTimeLeft = !showTimeLeft;
        Playable media = controller.getMedia();
        if (media == null) {
            return;
        }
        TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
        String length;
        if (showTimeLeft) {
            int remainingTime = converter.convert(media.getDuration() - media.getPosition());
            length = "-" + Converter.getDurationStringLong(remainingTime);
        } else {
            int duration = converter.convert(media.getDuration());
            length = Converter.getDurationStringLong(duration);
        }
        viewBinding.durationLabel.setText(length);
        UserPreferences.setShowRemainTimeSetting(showTimeLeft);
        Log.d("timeleft on click", showTimeLeft ? "true" : "false");
    });
    viewBinding.sbPosition.setOnSeekBarChangeListener(this);
    viewBinding.rewindButton.setOnClickListener(v -> onRewind());
    viewBinding.rewindButton.setOnLongClickListener(v -> {
        SkipPreferenceDialog.showSkipPreference(VideoplayerActivity.this, SkipPreferenceDialog.SkipDirection.SKIP_REWIND, null);
        return true;
    });
    viewBinding.playButton.setIsVideoScreen(true);
    viewBinding.playButton.setOnClickListener(v -> onPlayPause());
    viewBinding.fastForwardButton.setOnClickListener(v -> onFastForward());
    viewBinding.fastForwardButton.setOnLongClickListener(v -> {
        SkipPreferenceDialog.showSkipPreference(VideoplayerActivity.this, SkipPreferenceDialog.SkipDirection.SKIP_FORWARD, null);
        return false;
    });
    // To suppress touches directly below the slider
    viewBinding.bottomControlsContainer.setOnTouchListener((view, motionEvent) -> true);
    viewBinding.bottomControlsContainer.setFitsSystemWindows(true);
    viewBinding.videoView.getHolder().addCallback(surfaceHolderCallback);
    viewBinding.videoView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    setupVideoControlsToggler();
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    viewBinding.videoPlayerContainer.setOnTouchListener(onVideoviewTouched);
    viewBinding.videoPlayerContainer.getViewTreeObserver().addOnGlobalLayoutListener(() -> viewBinding.videoView.setAvailableSize(viewBinding.videoPlayerContainer.getWidth(), viewBinding.videoPlayerContainer.getHeight()));
}
Also used : Playable(de.danoeh.antennapod.model.playback.Playable) TimeSpeedConverter(de.danoeh.antennapod.core.util.TimeSpeedConverter) SuppressLint(android.annotation.SuppressLint)

Example 13 with Playable

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

the class VideoplayerActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    if (controller == null) {
        return false;
    }
    Playable media = controller.getMedia();
    boolean isFeedMedia = (media instanceof FeedMedia);
    // FeedMedia implies it belongs to a Feed
    menu.findItem(R.id.open_feed_item).setVisible(isFeedMedia);
    boolean hasWebsiteLink = getWebsiteLinkWithFallback(media) != null;
    menu.findItem(R.id.visit_website_item).setVisible(hasWebsiteLink);
    boolean isItemAndHasLink = isFeedMedia && ShareUtils.hasLinkToShare(((FeedMedia) media).getItem());
    boolean isItemHasDownloadLink = isFeedMedia && ((FeedMedia) media).getDownload_url() != null;
    menu.findItem(R.id.share_item).setVisible(hasWebsiteLink || isItemAndHasLink || isItemHasDownloadLink);
    menu.findItem(R.id.add_to_favorites_item).setVisible(false);
    menu.findItem(R.id.remove_from_favorites_item).setVisible(false);
    if (isFeedMedia) {
        menu.findItem(R.id.add_to_favorites_item).setVisible(!isFavorite);
        menu.findItem(R.id.remove_from_favorites_item).setVisible(isFavorite);
    }
    menu.findItem(R.id.set_sleeptimer_item).setVisible(!controller.sleepTimerActive());
    menu.findItem(R.id.disable_sleeptimer_item).setVisible(controller.sleepTimerActive());
    if (PictureInPictureUtil.supportsPictureInPicture(this)) {
        menu.findItem(R.id.player_go_to_picture_in_picture).setVisible(true);
    }
    menu.findItem(R.id.audio_controls).setIcon(R.drawable.ic_sliders);
    return true;
}
Also used : Playable(de.danoeh.antennapod.model.playback.Playable) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 14 with Playable

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

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectStreamNoStartNoPrepare.

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

Example 15 with Playable

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

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectLocalStartPrepare.

@Test
@UiThreadTest
public void testPlayMediaObjectLocalStartPrepare() 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);
                }
            } catch (AssertionFailedError e) {
                if (assertionError == null)
                    assertionError = e;
            } finally {
                countDownLatch.countDown();
            }
        }
    });
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
    Playable p = writeTestPlayable(playableFileUrl, PLAYABLE_LOCAL_URL);
    psmp.playMediaObject(p, false, 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)

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