use of org.telegram.ui.Components.VideoSeekPreviewImage in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoViewer method createVideoControlsInterface.
private void createVideoControlsInterface() {
videoPlayerControlFrameLayout = new VideoPlayerControlFrameLayout(containerView.getContext());
containerView.addView(videoPlayerControlFrameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
final VideoPlayerSeekBar.SeekBarDelegate seekBarDelegate = new VideoPlayerSeekBar.SeekBarDelegate() {
@Override
public void onSeekBarDrag(float progress) {
if (videoPlayer != null) {
if (!inPreview && videoTimelineView.getVisibility() == View.VISIBLE) {
progress = videoTimelineView.getLeftProgress() + (videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress()) * progress;
}
long duration = videoPlayer.getDuration();
if (duration == C.TIME_UNSET) {
seekToProgressPending = progress;
} else {
videoPlayer.seekTo((int) (progress * duration));
}
showVideoSeekPreviewPosition(false);
needShowOnReady = false;
}
}
@Override
public void onSeekBarContinuousDrag(float progress) {
if (videoPlayer != null && videoPreviewFrame != null) {
videoPreviewFrame.setProgress(progress, videoPlayerSeekbar.getWidth());
}
showVideoSeekPreviewPosition(true);
updateVideoSeekPreviewPosition();
}
};
final FloatSeekBarAccessibilityDelegate accessibilityDelegate = new FloatSeekBarAccessibilityDelegate() {
@Override
public float getProgress() {
return videoPlayerSeekbar.getProgress();
}
@Override
public void setProgress(float progress) {
seekBarDelegate.onSeekBarDrag(progress);
videoPlayerSeekbar.setProgress(progress);
videoPlayerSeekbarView.invalidate();
}
@Override
public String getContentDescription(View host) {
final String time = LocaleController.formatPluralString("Minutes", videoPlayerCurrentTime[0]) + ' ' + LocaleController.formatPluralString("Seconds", videoPlayerCurrentTime[1]);
final String totalTime = LocaleController.formatPluralString("Minutes", videoPlayerTotalTime[0]) + ' ' + LocaleController.formatPluralString("Seconds", videoPlayerTotalTime[1]);
return LocaleController.formatString("AccDescrPlayerDuration", R.string.AccDescrPlayerDuration, time, totalTime);
}
};
videoPlayerSeekbarView = new View(containerView.getContext()) {
@Override
protected void onDraw(Canvas canvas) {
videoPlayerSeekbar.draw(canvas, this);
}
};
videoPlayerSeekbarView.setAccessibilityDelegate(accessibilityDelegate);
videoPlayerSeekbarView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
videoPlayerControlFrameLayout.addView(videoPlayerSeekbarView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
videoPlayerSeekbar = new VideoPlayerSeekBar(videoPlayerSeekbarView);
videoPlayerSeekbar.setHorizontalPadding(AndroidUtilities.dp(2));
videoPlayerSeekbar.setColors(0x33ffffff, 0x33ffffff, Color.WHITE, Color.WHITE, Color.WHITE, 0x59ffffff);
videoPlayerSeekbar.setDelegate(seekBarDelegate);
videoPreviewFrame = new VideoSeekPreviewImage(containerView.getContext(), () -> {
if (needShowOnReady) {
showVideoSeekPreviewPosition(true);
}
}) {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
updateVideoSeekPreviewPosition();
}
@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
if (visibility == VISIBLE) {
updateVideoSeekPreviewPosition();
}
}
};
videoPreviewFrame.setAlpha(0.0f);
containerView.addView(videoPreviewFrame, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48 + 10));
videoPlayerTime = new SimpleTextView(containerView.getContext());
videoPlayerTime.setTextColor(0xffffffff);
videoPlayerTime.setGravity(Gravity.RIGHT | Gravity.TOP);
videoPlayerTime.setTextSize(14);
videoPlayerTime.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
videoPlayerControlFrameLayout.addView(videoPlayerTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.TOP, 0, 15, 12, 0));
exitFullscreenButton = new ImageView(containerView.getContext());
exitFullscreenButton.setImageResource(R.drawable.msg_minvideo);
exitFullscreenButton.setContentDescription(LocaleController.getString("AccExitFullscreen", R.string.AccExitFullscreen));
exitFullscreenButton.setScaleType(ImageView.ScaleType.CENTER);
exitFullscreenButton.setBackground(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
exitFullscreenButton.setVisibility(View.INVISIBLE);
videoPlayerControlFrameLayout.addView(exitFullscreenButton, LayoutHelper.createFrame(48, 48, Gravity.TOP | Gravity.RIGHT));
exitFullscreenButton.setOnClickListener(v -> {
if (parentActivity == null) {
return;
}
wasRotated = false;
fullscreenedByButton = 2;
if (prevOrientation == -10) {
prevOrientation = parentActivity.getRequestedOrientation();
}
parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
});
}
Aggregations