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)));
}
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()));
}
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;
}
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();
}
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();
}
Aggregations