原因:
视频修改完成后没有获取剪辑视频时间,并插入数据库
TrimVideo.java
public void run() {
try {
double trimVideoDuration = TrimVideoUtils.startTrim(mSrcFile, mDstFile, mTrimStartTime, mTrimEndTime);
// Update the database for adding a new video file.
insertContent(mDstFile, (int)(trimVideoDuration * 1000));
} catch (IOException e) {
.................
private Uri insertContent(File file, int duration) {
long nowInMs = System.currentTimeMillis();
long nowInSec = nowInMs / 1000;
final ContentValues values = new ContentValues(13);
values.put(Video.Media.TITLE, mSaveFileName);
values.put(Video.Media.DISPLAY_NAME, file.getName());
values.put(Video.Media.MIME_TYPE, "video/mp4");
values.put(Video.Media.DATE_TAKEN, nowInMs);
values.put(Video.Media.DATE_MODIFIED, nowInSec);
values.put(Video.Media.DATE_ADDED, nowInSec);
values.put(Video.Media.DATA, file.getAbsolutePath());
values.put(Video.Media.SIZE, file.length());
values.put(Video.Media.DURATION, duration);
// Copy the data taken and location info from src.
TrimVideoUtils.java
public static double startTrim(File src, File dst, int startMs, int endMs) throws IOException
....
double TrimVideoStartTime = Double.MAX_VALUE;
double TrimVideoEndTime = 0;
for (Track track : tracks) {
long currentSample = 0;
double currentTime = 0;
long startSample = -1;
long endSample = -1;
double trackStartTime = 0;
double trackEndTime = 0;
.......
if (currentTime <= startTime) {
// current sample is still before the new starttime
startSample = currentSample;
trackStartTime = currentTime;
}
if (currentTime <= endTime) {
// current sample is after the new start time and still before the new endtime
endSample = currentSample;
trackEndTime = currentTime;
} else {
// current sample is after the end of the cropped video
break;
}
currentTime += (double) entry.getDelta() / (double) track.getTrackMetaData().getTimescale();
currentSample++;
}
}
TrimVideoStartTime = Math.min(TrimVideoStartTime, trackStartTime);
TrimVideoEndTime = Math.max(TrimVideoEndTime,trackEndTime);
movie.addTrack(new CroppedTrack(track, startSample, endSample));
}
IsoFile out = new DefaultMp4Builder().build(movie);
if (!dst.exists()) {
dst.createNewFile();
}
FileOutputStream fos = new FileOutputStream(dst);
FileChannel fc = fos.getChannel();
out.getBox(fc); // This one build up the memory.
fc.close();
fos.close();
randomAccessFile.close();
return TrimVideoEndTime - TrimVideoStartTime;
}