Skip to content

Commit

Permalink
1. 添加配置:长按准备时间
Browse files Browse the repository at this point in the history
2. 合成视频时检查视频文件是否超过1秒才视为及格
  • Loading branch information
zhongjh committed Jun 4, 2024
1 parent ecbe5e7 commit 59d7f6f
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 16 deletions.
19 changes: 19 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,25 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="2000" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/press_and_hold_for_the_specified_time_to_start_recording" />

<EditText
android:id="@+id/etCameraReadinessDuration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="1000" />

</LinearLayout>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
<string name="take_pictures_in_hd">高清拍照(失去录像功能)</string>
<string name="take_video_in_hd">高清录像(失去拍照功能)</string>
<string name="maximum_recording_time">最长录制时间</string>
<string name="minimum_recording_time_milliseconds">最短录制时间(毫秒)</string>
<string name="minimum_recording_time_milliseconds">最短录制时间(毫秒),不能低于2000</string>
<string name="press_and_hold_for_the_specified_time_to_start_recording">长按达到设置时间后,才开启录制</string>
<string name="enable_recording">开启录音功能</string>
<string name="simple_version">简单版</string>
<string name="super_simple_version">超级简单版</string>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
<string name="take_pictures_in_hd">Take pictures in HD(Lost video recording function)</string>
<string name="take_video_in_hd">Take video in HD(Losing the ability to take pictures)</string>
<string name="maximum_recording_time">Maximum recording time</string>
<string name="minimum_recording_time_milliseconds">Minimum recording time (milliseconds)</string>
<string name="minimum_recording_time_milliseconds">Minimum recording time (milliseconds),Cannot be lower than 2000</string>
<string name="press_and_hold_for_the_specified_time_to_start_recording">press and hold for the specified time to start recording</string>
<string name="enable_recording">Enable recording</string>
<string name="simple_version">Simple version of</string>
<string name="super_simple_version">Super simple</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ protected void setView() {
getPhotoVideoLayout().setDuration(cameraSpec.getDuration() * 1000);
// 最短录制时间
getPhotoVideoLayout().setMinDuration(cameraSpec.getMinDuration());
getPhotoVideoLayout().setReadinessDuration(cameraSpec.getReadinessDuration());
}

/**
Expand Down Expand Up @@ -778,6 +779,14 @@ private void longClickShort(final long time) {
stopRecord(true);
}

/**
* 提示过短
*/
public void setShortTip() {
// 提示过短
getPhotoVideoLayout().setTipAlphaAnimation(getResources().getString(R.string.z_multi_library_the_recording_time_is_too_short));
}

/**
* 初始化中心按钮状态
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import static android.app.Activity.RESULT_OK;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.media.MediaMetadataRetriever;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

Expand Down Expand Up @@ -35,6 +38,7 @@
public class BaseCameraVideoPresenter implements ICameraVideo {

private final static int PROGRESS_MAX = 100;
private final static String TAG = "BaseCameraVideoPresenter";

public BaseCameraVideoPresenter(
BaseCameraFragment<? extends CameraStateManagement,
Expand Down Expand Up @@ -183,14 +187,22 @@ public void recordVideo() {
/**
* 视频录制结束后
*/
@SuppressLint("LongLogTag")
@Override
public void onVideoTaken(VideoResult result) {
// 判断文件是否超过1秒才属于合格的视频
long mediaDuration = getMediaDuration(result.getFile().getPath());
if (mediaDuration < 1000) {
baseCameraFragment.setShortTip();
Log.d(TAG,"视频时间低于1秒");
}
// 判断是否短时间结束
if (!isShort && !isBreakOff()) {
if (!isShort && !isBreakOff() && mediaDuration >= 1000) {
if (!isSectionRecord) {
// 如果录制结束,打开该视频。打开底部菜单
PreviewVideoActivity.startActivity(baseCameraFragment, previewVideoActivityResult, result.getFile().getPath());
} else {
Log.d(TAG, result.getFile().getPath() + " 是否存在:" + result.getFile().exists());
videoTimes.add(sectionRecordTime);
// 如果已经有录像缓存,那么就不执行这个动作了
if (videoPaths.size() <= 0) {
Expand Down Expand Up @@ -289,6 +301,29 @@ public void stopVideoMultiple() {
}
}

/**
* 获取视频的时间
*
* @param filePath 视频文件
* @return 视频的时间
*/
private long getMediaDuration(String filePath) {
try {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(filePath);
String metaData = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long duration = 0L;
if (metaData != null) {
duration = Long.parseLong(metaData);
}
retriever.close();
return duration;
} catch (Exception exception) {
exception.printStackTrace();
return 0;
}
}

public MediaStoreCompat getVideoMediaStoreCompat() {
return videoMediaStoreCompat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
mViewHolder.pvLayout.setDuration(mRecordSpec.getDuration() * 1000);
// 最短录制时间
mViewHolder.pvLayout.setMinDuration(mRecordSpec.getMinDuration());
mViewHolder.pvLayout.setReadinessDuration(mRecordSpec.getReadinessDuration());
// 设置只能长按
mViewHolder.pvLayout.setButtonFeatures(BUTTON_STATE_ONLY_LONG_CLICK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ object CameraSpec {
var duration = 10

/**
* 最短录制时间限制,单位为毫秒,即是如果长按在1500毫秒内,都暂时不开启录制
* 最短录制时间限制,单位为毫秒,如果录制期间低于2000毫秒,均不算录制
* 值不能低于2000,如果低于2000还是以2000为准
*/
var minDuration = 1500
var minDuration = 2000

/**
* 长按准备时间,单位为毫秒,即是如果长按在1000毫秒内,都暂时不开启录制
*/
var readinessDuration = 1000

/**
* 视频分段录制合并功能
Expand Down Expand Up @@ -152,8 +158,8 @@ object CameraSpec {
enableFlashMemoryModel = false
// 最长录制时间
duration = 10
// 最短录制时间限制,单位为毫秒,即是如果长按在1500毫秒内,都暂时不开启录制
minDuration = 1500
minDuration = 2000
readinessDuration = 1000
videoMergeCoordinator = null
watermarkResource = -1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ object RecordeSpec {
var duration = 10

/**
* 最短录制时间限制,单位为毫秒,即是如果长按在1500毫秒内,都暂时不开启录制
* 最短录制时间限制,单位为毫秒,如果录制期间低于2000毫秒,均不算录制
* 值不能低于2000,如果低于2000还是以2000为准
*/
var minDuration = 1500
var minDuration = 2000

/**
* 长按准备时间,单位为毫秒,即是如果长按在1000毫秒内,都暂时不开启录制
*/
var readinessDuration = 1000

// region end 属性

Expand All @@ -32,7 +38,8 @@ object RecordeSpec {
private fun reset() {
// 最长录制时间
duration = 10
// 最短录制时间限制,单位为毫秒,即是如果长按在1500毫秒内,都暂时不开启录制
minDuration = 1500
// 最短录制时间限制,单位为毫秒,如果录制期间低于2000毫秒,均不算录制
minDuration = 2000
readinessDuration = 1000
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,22 @@ public void setDuration(int duration) {
/**
* 最短录制时间
*
* @param duration 时间
* @param duration 时间毫秒
*/
public void setMinDuration(int duration) {
viewHolder.btnClickOrLong.setMinDuration(duration);
}

/**
* 长按准备时间
* 长按达到duration时间后,才开启录制
*
* @param duration 时间毫秒
*/
public void setReadinessDuration(int duration) {
viewHolder.btnClickOrLong.setReadinessDuration(duration);
}

/**
* 重置本身全部
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class ClickOrLongButton extends View {
/**
* 最短录制时间限制
*/
private int mMinDuration = 1500;
private int mMinDuration = 2000;
/**
* 动画的预备时间
*/
Expand Down Expand Up @@ -510,7 +510,7 @@ public boolean onTouchEvent(MotionEvent event) {
case MotionEvent.ACTION_UP:
if (mButtonState == BUTTON_STATE_CLICK_AND_HOLD) {
// 点击即长按模式
if (recordState != RECORD_STARTED) {
if (recordState == RECORD_NOT_STARTED) {
// 未启动状态,即立刻启动长按动画
step = STEP_ACTION_DOWN;
startTicking();
Expand Down Expand Up @@ -698,11 +698,23 @@ public void setDuration(int duration) {
* @param duration 时间
*/
public void setMinDuration(int duration) {
mMinDuration = duration;
if (duration > mMinDuration) {
mMinDuration = duration;
}
}

/**
* 长按准备时间
* 长按达到duration时间后,才开启录制
*
* @param duration 时间
*/
public void setReadinessDuration(int duration) {
mMinDurationAnimation = duration;
mMinDurationAnimationCurrent = mMinDurationAnimation;
}


/**
* 设置当前已录制的时间,用于分段录制
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder
import com.googlecode.mp4parser.authoring.container.mp4.MovieCreator
import com.googlecode.mp4parser.authoring.tracks.AppendTrack
import com.zhongjh.common.coordinator.VideoMergeCoordinator
import java.io.File
import java.io.IOException
import java.io.RandomAccessFile
import java.nio.channels.FileChannel
Expand All @@ -33,7 +34,6 @@ class VideoMergeManager : VideoMergeCoordinator {
val mp4MovieList: MutableList<Movie> = ArrayList()
// 将每个文件路径都构建成一个Movie对象
for (mp4Path in mp4PathList) {
Log.d(tag, "视频路径: $mp4Path")
mp4MovieList.add(MovieCreator.build(mp4Path))
}
// 音频通道集合
Expand Down

0 comments on commit 59d7f6f

Please sign in to comment.