How can we avoid the tragedy when the system time changes during the video recording process?

Source: Internet
Author: User

How can we avoid the tragedy when the system time changes during the video recording process?

 

On the Android system, we know there are two ways to change the system time: one is to set the date and time in the application, and the other is to synchronize the time through the network background, there are a lot of these two types of mobile phone tablets. Of course, as a vehicle-mounted device, GPS time is usually used to synchronize the system time. There are several ways to change the system time, But what harm does the system time change during the video recording process?

Through the author's experiment, if the video starts at on January 1, May 20, 2014, after a minute, the system has been synchronized and modified through the network until January 1, July 1, 2014, even if the video file is actually recorded for only five minutes, the total time of the video file displayed when we play back the file will be a relatively large exception.

/*************************************** **************************************** **********************/
Statement: the content of this blog is created at http://blog.csdn.net/edsam49. please refer to it for help. Thank you!
/*************************************** **************************************** **********************/

Because during video file encoding, most of the end time will still be written to an end time point, which uses the system time, instead of the system time for starting video recording and the video duration. In this way, problems may occur. How can we avoid it?

In my practical work, I used the car recorder, and the system time changed through systemclock. setcurrenttimemillis (millis); modified, so we can do something before and after calling this interface. Of course, it is not feasible to directly put it in systemclock. Java, because it is only a common interface of LIB and there is no object in it.

By setting the time when the application is modified, it will eventually go to the public voidsettime (long millis) interface in alarmmanagerservice. java. I wrote a database to store data before and after the call, and listened to the data modification in the driving record, so that the video can be stopped before the modification time, after the system time modification is completed, start a new video.

     public void setTime(longmillis) {       mContext.enforceCallingOrSelfPermission(               "android.permission.SET_TIME",               "setTime");            Settings.System.putInt(mContext.getContentResolver(),Settings.System.SET_SYTEM_TIME_STATUS, 0);                        try        {          Thread.currentThread().sleep(100);//100ms        }           catch(Exceptione){}        SystemClock.setCurrentTimeMillis(millis);             Settings.System.putInt(mContext.getContentResolver(),Settings.System.SET_SYTEM_TIME_STATUS, 1);                   }

In addition, the networktimeupdateservice. Java file can be used to modify the system time.

Listen to the status of this database value in the video application, and then receive a notification of value change in this content observer. After receiving this notification, you can stop the current video, wait for the value in the database to change, that is, the value set after the system time is set, and restart the video in the listener interface.

Private Final extends contentobserver {publicsettingsobserver (handler) {super (handler) ;}@ override public voidonchange (Boolean selfchange, Uri URI) {// synchronized (mlock) {// handlesettingschangedlocked (); audio_out_channel_src = settings. system. getint (Resolver, settings. system. set_sytem_time_status, 5); log. D ("deshengdiy", "settingsobserveronchange audio_out_channel_src" + audio_out_channel_src); // after the system time is set, restart the video} resolver = getcontentresolver (); msettingsobserver = newsettingsobserver (mhandler); resolver. registercontentobserver (settings. system. geturifor (settings. system. set_sytem_time_status), false, msettingsobserver );

It turns out that such processing is simple and effective.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.