I think you need to do some record, eg, record one min,then call stop and
see the stop time
在 2012年7月19日星期四UTC+8上午6时19分19秒,bob写道:
>
> I tried this code on a Samsung Galaxy S3:
>
> package com.example.media_test;
>
> import java.io.IOException;
>
> import android.media.MediaRecorder;
> import android.os.Bundle;
> import android.app.Activity;
> import android.view.Menu;
> import android.view.MenuItem;
> import android.support.v4.app.NavUtils;
>
> public class MainActivity extends Activity {
>
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
>
> setContentView(R.layout.activity_main);
>
> MediaRecorder recorder = new MediaRecorder();
> recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
> recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
> recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
> recorder.setOutputFile("/mnt/sdcard/bla");
> try {
> recorder.prepare();
> } catch (IllegalStateException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> long start = System.currentTimeMillis();
> recorder.start(); // Recording is now started
>
> try {
> Thread.sleep(500);
> } catch (InterruptedException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> recorder.stop();
> long end = System.currentTimeMillis();
> System.out.println("cost : " + (end - start));
> }
>
> @Override
> public boolean onCreateOptionsMenu(Menu menu) {
> getMenuInflater().inflate(R.menu.activity_main, menu);
> return true;
> }
>
> }
>
>
> The cost was only 833, and that's with 500 ms of sleep. Seems reasonable.
>
> Maybe you need a better phone?
>
> Also, remember to have these permissions:
>
> <uses-permission android:name="android.permission.RECORD_AUDIO"/>
> <uses-permission
> android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
>
>
>
>
> On Monday, July 16, 2012 5:43:41 AM UTC-5, luckywizard wrote:
>>
>> MediaRecorder mRecorder;
>>
>> long start = System.currentTimeMillis();
>> mRecorder.stop();
>> long end= System.currentTimeMillis();
>> System.out.println("cost : " + (end - start));
>>
>>
>>
>> the output is "cost 6065",
>> this is too long, how can i fix this prob.
>>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en