) An error occurred while releasing resources in audiorecord (unexpected process interruption)

Source: Internet
Author: User
Releasing resources is called audiorecord. the release () method is a function that you just thought of in the previous two days. It is actually written, and it is the method you want to release the resources currently occupied. However, you may encounter various problems during use, if it is not applicable, the problem becomes more serious.

 

Currently, the release method is not considered in many online audiorecord explanations, or some methods in Google Code do not require release resources. However, the release of MIC resources is a required requirement, especially when calls are made. Therefore, the release method must be used to release the mic resources.

 

I personally feel a wide variety of popular network versions in http://blog.csdn.net/zhjp4295216/archive/2010/11/09/5996735. aspx is a reliable one, but it means that the release of MIC resources cannot be completely released, and there may be intermittent calls. However, it is good to use it as a reference version.

 

Let's take a look at the introduction on the API:
Public void release ()
Since: API level 3

Releases the native audiorecord resources. The object can no longer be used and the reference shocould be set to null after a call to release ()

 

You must think this explanation is very annoying. At least I think so. According to the result I used, it should mean:

After the object is released, it cannot be used again and the reference must be changed to null. It's just translation, but it doesn't mean translation.

Two Basic Error Methods:

1. Process the recording in a thread, inherit the method release provided in the Thread class, stop before the call, and then release.

2. Like the URL, but add the release at the end of run. Start

 

The two examples are certainly incorrect. Let's talk about the problem first.

1. Stop, suspend, and then release. In essence, the audiorecord operation is not over yet, but it must be forcibly disabled (the stop method itself is not secure ). It will continue to occupy the mic, so the release will cause the thread to end unexpectedly, and the system reports the thread to be interrupted unexpectedly. This is the reference shocould be set to null. Although the system will automatically enable the incoming call for you again, it will not always let the user see it every time.ProgramInterrupt.

2. After pause is removed, the program is normally concealed, but the program will call record again at start, although a new one is generated. This is the object can no longer be used and the reference shocould be set to null. Therefore, the same error will be thrown when you return to the program again.

 

Here the solution is obvious, that is, add ar. Release (); at the end of the run of the Instance program ();. When the call ends, a new thread is generated to end the original thread! In this way, the MIC can be successfully released again and in the background. I hope to explain these two errors so that you can understand the sentence and the tangle error thrown by the system.

 

In addition, there is an error in that instance. You must have seen it. Let's just say that there are too many online errors:

Public void start (){
// Call in onresume of the activity that calls this thread so that the activity resumes obtaining the microphone input volume
If (! Isrun ){
Super. Start ();
Isrun = true;
}
}

 

Note: many recordings cannot be tested on the simulator. Therefore, please test on the real machine. This is why the source error cannot be found.

Private Final Static int channel_mode = audioformat. channel_configuration_mono;
Private Final Static int encoding = audioformat. encoding_pcm_8bit;

Recorder = new audiorecord (mediarecorder. audiosource. Mic, rate,
Channel_mode, encoding, chunk_size_in_samples * 2 );

 

I remember it only seems to support this. The frequency is the lowest. At least 44100 is not supported. You can test it using audiorecord. getminbuffersize. Someone has made statistics on a foreign website, but I can't find it. I forgot to save it and can only share it. Okay, that's all.

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.