Skip to content

Commit

Permalink
update seek bar
Browse files Browse the repository at this point in the history
update seek bar
  • Loading branch information
Ahmedbadereldin committed Dec 12, 2022
1 parent b2adebc commit 82ea8ba
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ public class VideoTrimmerActivity extends AppCompatActivity implements View.OnCl
private TextView txtVideoLength;

private int mDuration = 0;
private int mDurationWithoutEdit = 0;
private int mTimeVideo = 0;
private int mStartPosition = 0;
private int mEndPosition = 0;
// set your max video trim seconds
private int mMaxDuration = 60;
private int mMaxDuration = 120;
private Handler mHandler = new Handler();

private ProgressDialog mProgressDialog;
Expand Down Expand Up @@ -199,8 +200,24 @@ public void onStartTrackingTouch(SeekBar seekBar) {

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Log.d("onStopTrackingTouch", "onStopTrackingTouch: 123123123 ---> " + (mStartPosition * 1000) + " <-----> " + seekBar.getProgress() + " <-----> " + seekBarVideo.getProgress());
Log.d("onStopTrackingTouch", "onStopTrackingTouch: 123123123 ---> " + (mDuration * 1000) + " <-----> " + seekBarVideo.getProgress());
Log.d("onStopTrackingTouch", "onStopTrackingTouch: 123123123 ---> " + ((mStartPosition * 1000) - seekBarVideo.getProgress()));
Log.d("onStopTrackingTouch", "onStopTrackingTouch: 123123123 ---> " + ((mDuration * 1000) - seekBarVideo.getProgress()));
Log.d("onStopTrackingTouch", "onStopTrackingTouch: 123123123 mVideoView---> " + mVideoView.getDuration());
Log.d("onStopTrackingTouch", "onStopTrackingTouch: 123123123 seekBar---> " + seekBar.getProgress());
Log.d("onStopTrackingTouch", "onStopTrackingTouch: 123123123 mStartPosition---> " + (mStartPosition*1000));
Log.d("onStopTrackingTouch", "onStopTrackingTouch: 123123123 mEndPosition---> " + (mEndPosition*1000));

// seek bar - 120 sec
// start = 130
// end = 255

// if(mDuration)
mHandler.removeCallbacks(mUpdateTimeTask);
mVideoView.seekTo((mStartPosition * 1000) - seekBarVideo.getProgress());
// mVideoView.seekTo((mDuration * 1000) - seekBarVideo.getProgress());
mVideoView.seekTo((mStartPosition*1000) + seekBar.getProgress());
// mVideoView.start();
}
});
}
Expand Down Expand Up @@ -235,7 +252,7 @@ public void execute() {
"executeAAAA",
"execute: " + "Aaaa" + file.length() + " " + dstFile + " " + mStartPosition + " " + mEndPosition + " " + mOnVideoTrimListener
);
Utility.startTrim(VideoTrimmerActivity.this,file, dstFile, mStartPosition * 1000, mEndPosition * 1000, mOnVideoTrimListener);
Utility.startTrim(VideoTrimmerActivity.this, file, dstFile, mStartPosition * 1000, mEndPosition * 1000, mOnVideoTrimListener);
} catch (final Throwable e) {
Objects.requireNonNull(Thread.getDefaultUncaughtExceptionHandler()).uncaughtException(Thread.currentThread(), e);
}
Expand All @@ -259,6 +276,9 @@ public void execute() {
if (seekBarVideo.getProgress() == 0) {
txtVideoLength.setText("00:00");
updateProgressBar();
}else{
txtVideoLength.setText(milliSecondsToTimer(seekBarVideo.getProgress()) + "");
updateProgressBar();
}
}
}
Expand All @@ -269,6 +289,7 @@ private void setBitmap(Uri mVideoUri) {
tileView.setVideo(mVideoUri);
}

//region todo onVideoPrepared
private void onVideoPrepared(@NonNull MediaPlayer mp) {
// Adjust the size of the video
// so it fits on the screen
Expand All @@ -290,9 +311,11 @@ private void onVideoPrepared(@NonNull MediaPlayer mp) {
}
mVideoView.setLayoutParams(lp);*/

//mVideoView.getDuration() => get in msec we need it in sec
mDuration = mVideoView.getDuration() / 1000;
setSeekBarPosition();
}
//endregion

public void updateProgressBar() {
mHandler.postDelayed(mUpdateTimeTask, 100);
Expand All @@ -316,6 +339,7 @@ public void run() {
}
};

//region todo setSeekBarPosition
private void setSeekBarPosition() {

if (mDuration >= mMaxDuration) {
Expand All @@ -324,16 +348,20 @@ private void setSeekBarPosition() {

mCustomRangeSeekBarNew.setThumbValue(0, (mStartPosition * 100) / mDuration);
mCustomRangeSeekBarNew.setThumbValue(1, (mEndPosition * 100) / mDuration);

//////
mDurationWithoutEdit = mDuration;
// mDuration = mMaxDuration;
} else {
mStartPosition = 0;
mEndPosition = mDuration;
mDurationWithoutEdit = mDuration;
}


mTimeVideo = mDuration;
mCustomRangeSeekBarNew.initMaxWidth();
seekBarVideo.setMax(mMaxDuration * 1000);
// seekBarVideo.setMax(mMaxDuration * 1000);
seekBarVideo.setMax(mDurationWithoutEdit * 1000);
mVideoView.seekTo(mStartPosition * 1000);

String mStart = mStartPosition + "";
Expand All @@ -352,6 +380,7 @@ private void setSeekBarPosition() {

txtVideoTrimSeconds.setText(String.format(Locale.US, "%02d:%02d - %02d:%02d", startMin, startSec, endMin, endSec));
}
//endregion

/**
* called when playing video completes
Expand Down

0 comments on commit 82ea8ba

Please sign in to comment.