In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how Android can use mobile phone camera to limit the length of video recording. I hope you will get something after reading this article. Let's discuss it together.
The details are as follows
Because the server space is limited, the duration of the video must be limited.
First lay out a button in xml and click to start recording. Layout a TextView to display the countdown time.
1. Use Hander+TimerTask to complete timing operation
Private TextView btn_stop;private int recLen = 11 timer timer = new Timer (); / / the countdown is placed after the start button event, see heading 7 where the countdown begins / / timer.schedule (task,1000,1000) Final Handler handler = new Handler () {@ Override public void handleMessage (Message msg) {switch (msg.what) {case 1: btn_stop.setText ("" + recLen); if (recLen 2 * 1024 * 1024) {mediaRecorder.setVideoEncodingBitRate (2 * 1024 * 1024);} else {mediaRecorder.setVideoEncodingBitRate (1024 * 1024) } mediaRecorder.setVideoFrameRate (mProfile.videoFrameRate); mediaRecorder.setVideoSize (1280); mediaRecorder.setOutputFile (mVecordFile.getAbsolutePath ());}
5. Stop recording
Private void stopRecord () {try {if (isRecording & & mediaRecorder! = null) {mediaRecorder.setOnErrorListener (null); mediaRecorder.setPreviewDisplay (null); mediaRecorder.stop (); mediaRecorder.reset (); mediaRecorder.release (); mediaRecorder = null; isRecording = false Log.i (TAG, "" + mVecordFile.toString ()); / / new imageTask (). Execute (mVecordFile); MessageData md = new MessageData (); md.srdatatype = SRDataType. Video is returned; md.Data = mVecordFile.getAbsolutePath (); Intent intent = new Intent (BroadCastParameter.action); intent.putExtra ("data", md); sendBroadcast (intent); / / Fragment page broadcast notification LocalBroadcastManager.getInstance (CustomRecorder.this) .sendbroadcast (intent); finish () } catch (Exception ex) {/ / Toast.makeText (getApplicationContext (), ex.getMessage (), 1). Show ();}}
Turn off the camera
Private void stopCamera () {if (mCamera! = null) {mCamera.setPreviewCallback (null); mCamera.stopPreview (); mCamera.release (); mCamera = null;}}
Click the start recording button
Public void onViewClicked (View view) {if (Build.VERSION.SDK_INT > = 23) {int REQUEST_CODE_CONTACT = 101 / / verify whether for (String str: permissions) {if (this.checkSelfPermission (str)! = PackageManager.PERMISSION_GRANTED) {Toast.makeText (getApplicationContext (), "Storage permission is not authorized", 1) .show (); return } switch (view.getId ()) {/ / start case R.id.btn_start: btn_start.setVisibility (View.GONE); btn_stop.setVisibility (View.VISIBLE) / / this is to determine whether the video file has been created. If not, return boolean creakOk = createRecordDir (); if (! creakOk) {return;} try {mCamera.unlock (); setConfigRecord () MediaRecorder.prepare (); mediaRecorder.start ();} catch (Exception e) {/ / Toast.makeText (getApplicationContext (), e.getMessage (), Toast.LENGTH_LONG). Show ();} StartTime = new Date (System.currentTimeMillis ()); isRecording = true CustomTimer.ReStart (); timer.schedule (task,1000,1000); break; has read this article. I believe you have a certain understanding of "how to use mobile phone camera to limit the length of video recording". If you want to know more about it, welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.