Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Added Max Duration #27

Merged
merged 1 commit into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions library/src/main/java/com/gowtham/library/ui/ActVideoTrimmer.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public class ActVideoTrimmer extends AppCompatActivity{

private String fileName;

private int maxDuration;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -210,17 +212,18 @@ private void validate() {
assert trimVideoOptions != null;
trimType = TrimmerUtils.getTrimType(trimVideoOptions.trimType);
destinationPath = trimVideoOptions.destination;
fileName=trimVideoOptions.fileName;
fileName = trimVideoOptions.fileName;
hidePlayerSeek = trimVideoOptions.hideSeekBar;
isAccurateCut = trimVideoOptions.accurateCut;
compressOption = trimVideoOptions.compressOption;
fixedGap = trimVideoOptions.fixedDuration;
fixedGap = fixedGap != 0 ? fixedGap : totalDuration;
minGap = trimVideoOptions.minDuration;
minGap = minGap != 0 ? minGap : totalDuration;
maxDuration = trimVideoOptions.maxDuration;
if (trimType == 3) {
minFromGap = trimVideoOptions.minToMax[0];
maxToGap = trimVideoOptions.minToMax[1];
maxToGap = maxDuration > 0 ? maxDuration : trimVideoOptions.minToMax[1];
minFromGap = minFromGap != 0 ? minFromGap : totalDuration;
maxToGap = maxToGap != 0 ? maxToGap : totalDuration;
}
Expand Down Expand Up @@ -355,12 +358,27 @@ private void setImageBitmaps() {
if (!hidePlayerSeek)
seekbarController.setVisibility(View.INVISIBLE);
}
lastMinValue = minVal;
lastMaxValue = maxVal;
txtStartDuration.setText(TrimmerUtils.formatSeconds(minVal));
txtEndDuration.setText(TrimmerUtils.formatSeconds(maxVal));
int difference = maxValue.intValue() - minValue.intValue();
if (maxDuration > 0 && difference > maxDuration) // maxDuration = 60
{
if (lastMaxValue != maxValue.intValue()) {
lastMaxValue = lastMinValue + maxDuration;
seekbar.setMaxStartValue(lastMaxValue);
seekbar.apply();

} else if (lastMinValue != minValue.intValue()) {
lastMinValue = lastMaxValue - maxDuration;
seekbar.setMinStartValue(lastMinValue);
seekbar.apply();
}
} else {
lastMinValue = minVal;
lastMaxValue = maxVal;
}
txtStartDuration.setText(TrimmerUtils.formatSeconds(lastMinValue));
txtEndDuration.setText(TrimmerUtils.formatSeconds(lastMaxValue));
if (trimType == 3)
setDoneColor(minVal, maxVal);
setDoneColor(lastMinValue, lastMaxValue);
});

seekbarController.setOnSeekbarFinalValueListener(value -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public ActivityBuilder setDestination(final String destination) {
return this;
}

public ActivityBuilder setMaxDuration(int maxDuration) {
options.maxDuration = maxDuration;
return this;
}

public void start(Activity activity) {
validate();
activity.startActivityForResult(getIntent(activity), VIDEO_TRIMMER_REQ_CODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class TrimVideoOptions implements Parcelable {

public CompressOption compressOption;

public int maxDuration;

public TrimVideoOptions() {
}

Expand All @@ -39,6 +41,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte(this.hideSeekBar ? (byte) 1 : (byte) 0);
dest.writeByte(this.accurateCut ? (byte) 1 : (byte) 0);
dest.writeLongArray(this.minToMax);
dest.writeInt(this.maxDuration);
dest.writeParcelable(this.compressOption, flags);
}

Expand All @@ -52,6 +55,7 @@ protected TrimVideoOptions(Parcel in) {
this.hideSeekBar = in.readByte() != 0;
this.accurateCut = in.readByte() != 0;
this.minToMax = in.createLongArray();
this.maxDuration = in.readInt();
this.compressOption = in.readParcelable(CompressOption.class.getClassLoader());
}

Expand Down