Search in sources :

Example 1 with TimeSpeedConverter

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

the class AudioPlayerFragment method updatePosition.

@Subscribe(threadMode = ThreadMode.MAIN)
public void updatePosition(PlaybackPositionEvent event) {
    if (controller == null || txtvPosition == null || txtvLength == null || sbPosition == null) {
        return;
    }
    TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
    int currentPosition = converter.convert(event.getPosition());
    int duration = converter.convert(event.getDuration());
    int remainingTime = converter.convert(Math.max(event.getDuration() - event.getPosition(), 0));
    currentChapterIndex = ChapterUtils.getCurrentChapterIndex(controller.getMedia(), currentPosition);
    Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition));
    if (currentPosition == PlaybackService.INVALID_TIME || duration == PlaybackService.INVALID_TIME) {
        Log.w(TAG, "Could not react to position observer update because of invalid time");
        return;
    }
    txtvPosition.setText(Converter.getDurationStringLong(currentPosition));
    showTimeLeft = UserPreferences.shouldShowRemainingTime();
    if (showTimeLeft) {
        txtvLength.setText(((remainingTime > 0) ? "-" : "") + Converter.getDurationStringLong(remainingTime));
    } else {
        txtvLength.setText(Converter.getDurationStringLong(duration));
    }
    if (!sbPosition.isPressed()) {
        float progress = ((float) event.getPosition()) / event.getDuration();
        sbPosition.setProgress((int) (progress * sbPosition.getMax()));
    }
}
Also used : TimeSpeedConverter(de.danoeh.antennapod.core.util.TimeSpeedConverter) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with TimeSpeedConverter

use of de.danoeh.antennapod.core.util.TimeSpeedConverter 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 3 with TimeSpeedConverter

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

the class VideoplayerActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    if (controller == null) {
        return;
    }
    if (fromUser) {
        prog = progress / ((float) seekBar.getMax());
        TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
        int position = converter.convert((int) (prog * controller.getDuration()));
        viewBinding.seekPositionLabel.setText(Converter.getDurationStringLong(position));
    }
}
Also used : TimeSpeedConverter(de.danoeh.antennapod.core.util.TimeSpeedConverter) SuppressLint(android.annotation.SuppressLint)

Example 4 with TimeSpeedConverter

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

the class VideoplayerActivity method onPositionObserverUpdate.

void onPositionObserverUpdate() {
    if (controller == null) {
        return;
    }
    TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
    int currentPosition = converter.convert(controller.getPosition());
    int duration = converter.convert(controller.getDuration());
    int remainingTime = converter.convert(controller.getDuration() - controller.getPosition());
    Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition));
    if (currentPosition == PlaybackService.INVALID_TIME || duration == PlaybackService.INVALID_TIME) {
        Log.w(TAG, "Could not react to position observer update because of invalid time");
        return;
    }
    viewBinding.positionLabel.setText(Converter.getDurationStringLong(currentPosition));
    if (showTimeLeft) {
        viewBinding.durationLabel.setText("-" + Converter.getDurationStringLong(remainingTime));
    } else {
        viewBinding.durationLabel.setText(Converter.getDurationStringLong(duration));
    }
    updateProgressbarPosition(currentPosition, duration);
}
Also used : TimeSpeedConverter(de.danoeh.antennapod.core.util.TimeSpeedConverter) SuppressLint(android.annotation.SuppressLint)

Example 5 with TimeSpeedConverter

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

the class AudioPlayerFragment method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    if (controller == null || txtvLength == null) {
        return;
    }
    if (fromUser) {
        float prog = progress / ((float) seekBar.getMax());
        TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
        int position = converter.convert((int) (prog * controller.getDuration()));
        int newChapterIndex = ChapterUtils.getCurrentChapterIndex(controller.getMedia(), position);
        if (newChapterIndex > -1) {
            if (!sbPosition.isPressed() && currentChapterIndex != newChapterIndex) {
                currentChapterIndex = newChapterIndex;
                position = (int) controller.getMedia().getChapters().get(currentChapterIndex).getStart();
                seekedToChapterStart = true;
                controller.seekTo(position);
                updateUi(controller.getMedia());
                sbPosition.highlightCurrentChapter();
            }
            txtvSeek.setText(controller.getMedia().getChapters().get(newChapterIndex).getTitle() + "\n" + Converter.getDurationStringLong(position));
        } else {
            txtvSeek.setText(Converter.getDurationStringLong(position));
        }
    } else if (duration != controller.getDuration()) {
        updateUi(controller.getMedia());
    }
}
Also used : TimeSpeedConverter(de.danoeh.antennapod.core.util.TimeSpeedConverter)

Aggregations

TimeSpeedConverter (de.danoeh.antennapod.core.util.TimeSpeedConverter)6 SuppressLint (android.annotation.SuppressLint)3 Playable (de.danoeh.antennapod.model.playback.Playable)1 Subscribe (org.greenrobot.eventbus.Subscribe)1