I recorded a video using android Mediarecorder.
(Main Problem: I need to know the exact startTime[System time] and endTime[System time] of the video and the [endTime - startTime] must match the duration of the actual video)
MediaRecorder.start
startTime = System.currentTimeMillis()
then on stop
MediaRecorder.stop
endTime = System.currentTimeMillis()
I am expecting the video to have this duration
expected_duration = (endTime - startTime)
However, the
expected_duration is always more than the actual duration of the video.
My suspicion is that MediaRecorder.start is slow, it took some time before it actually started writing the frames into a video.
So now, is there anyway to get notified when the MediaRecorder started writing the first frame into a video? or is there any way I can figure out the exact System startTime of when video actually started recording.
thanks for reading, and appreciate any comments, opinions or suggestions. ^^
The best way I found to get real start time (and still I'm not sure it's accurate enough) is to find the duration and then subtract it from the endTime like that:
MediaRecorder.stop
endTime = System.currentTimeMillis()
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//use one of overloaded setDataSource() functions to set your data source
retriever.setDataSource(this, Uri.fromFile(file));
String time =
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long movieDurationInMillis = Long.parseLong(time );
long startCaptureTimeMillis = endTime - movieDurationInMillis;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With