desc:录制中的视频不展示在历史视频中

main
xiaowusky 2 years ago
parent 91054ba593
commit 5421ad151c

@ -3,6 +3,7 @@ package com.yinuo.library.vlc.encoder;
import android.media.MediaCodec;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import android.text.TextUtils;
import com.common.commonlib.db.DBUtils;
import com.common.commonlib.db.entity.Video;
@ -29,8 +30,10 @@ public class AndroidMuxer {
private volatile int mNumReleases;
private long mStartRecordTime = 0L;
private String mCurrentPath;
private long mRecordTime = -1;
private static final long DEFAULT_RECORD_DURATION = 30 * 60 * 1000;
// private static final long DEFAULT_RECORD_DURATION = 10 * 1000;
public AndroidMuxer() {
createMediaMuxer();
@ -40,11 +43,11 @@ public class AndroidMuxer {
try {
long timeMillis = System.currentTimeMillis();
File output = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO, timeMillis, DEFAULT_RECORD_DURATION);
String filePath = output.getAbsolutePath();
mCurrentPath = output.getAbsolutePath();
mRecordTime = timeMillis;
LogUtils.v(String.format("startRecording: %s", output));
mMuxer = new MediaMuxer(filePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mMuxer = new MediaMuxer(mCurrentPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mStarted = false;
insertToDB(timeMillis, filePath);
} catch (IOException e) {
e.printStackTrace();
}
@ -86,8 +89,7 @@ public class AndroidMuxer {
} else {
long recordTime = System.currentTimeMillis() - mStartRecordTime;
if (recordTime > DEFAULT_RECORD_DURATION) {
mMuxer.stop();
mMuxer.release();
stopMuxer();
mNumTracks = 0;
mStartRecordTime = 0L;
@ -100,11 +102,18 @@ public class AndroidMuxer {
public boolean release() {
synchronized (mMuxer) {
if (++mNumReleases == mNumTracks) {
mMuxer.stop();
mMuxer.release();
stopMuxer();
return true;
}
}
return false;
}
public void stopMuxer() {
mMuxer.stop();
mMuxer.release();
if (mRecordTime > 0 && mRecordTime < System.currentTimeMillis() && !TextUtils.isEmpty(mCurrentPath)) {
insertToDB(mRecordTime, mCurrentPath);
}
}
}

Loading…
Cancel
Save