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.MediaCodec;
import android.media.MediaFormat; import android.media.MediaFormat;
import android.media.MediaMuxer; import android.media.MediaMuxer;
import android.text.TextUtils;
import com.common.commonlib.db.DBUtils; import com.common.commonlib.db.DBUtils;
import com.common.commonlib.db.entity.Video; import com.common.commonlib.db.entity.Video;
@ -29,8 +30,10 @@ public class AndroidMuxer {
private volatile int mNumReleases; private volatile int mNumReleases;
private long mStartRecordTime = 0L; 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 = 30 * 60 * 1000;
// private static final long DEFAULT_RECORD_DURATION = 10 * 1000;
public AndroidMuxer() { public AndroidMuxer() {
createMediaMuxer(); createMediaMuxer();
@ -40,11 +43,11 @@ public class AndroidMuxer {
try { try {
long timeMillis = System.currentTimeMillis(); long timeMillis = System.currentTimeMillis();
File output = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO, timeMillis, DEFAULT_RECORD_DURATION); 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)); 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; mStarted = false;
insertToDB(timeMillis, filePath);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -86,8 +89,7 @@ public class AndroidMuxer {
} else { } else {
long recordTime = System.currentTimeMillis() - mStartRecordTime; long recordTime = System.currentTimeMillis() - mStartRecordTime;
if (recordTime > DEFAULT_RECORD_DURATION) { if (recordTime > DEFAULT_RECORD_DURATION) {
mMuxer.stop(); stopMuxer();
mMuxer.release();
mNumTracks = 0; mNumTracks = 0;
mStartRecordTime = 0L; mStartRecordTime = 0L;
@ -100,11 +102,18 @@ public class AndroidMuxer {
public boolean release() { public boolean release() {
synchronized (mMuxer) { synchronized (mMuxer) {
if (++mNumReleases == mNumTracks) { if (++mNumReleases == mNumTracks) {
mMuxer.stop(); stopMuxer();
mMuxer.release();
return true; return true;
} }
} }
return false; return false;
} }
public void stopMuxer() {
mMuxer.stop();
mMuxer.release();
if (mRecordTime > 0 && mRecordTime < System.currentTimeMillis() && !TextUtils.isEmpty(mCurrentPath)) {
insertToDB(mRecordTime, mCurrentPath);
}
}
} }

Loading…
Cancel
Save