2011-10-31 59 views
20

我正在使用android.provider.MediaStore.ACTION_VIDEO_CAPTURE。我想知道是否有办法改变每次录制所允许的最长时间。我试图添加 Intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60000);//max of 60 seconds 但它继续记录传递。提前致谢。是否可以使用intent设置允许的最大时间android记录?

+3

请注意MediaStore.EXTRA_DURATION_LIMIT是以秒为单位给出的,而不是毫秒。但它只适用于2.0后的设备。 – user953768

回答

2

使用MediaRecorder

/** 
    * Starts a new recording. 
    */ 
    public void start() throws IOException { 

    recorder = new MediaRecorder(); 

    String state = android.os.Environment.getExternalStorageState(); 

    if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) { 
     throw new IOException("SD Card is not mounted. It is " + state 
      + "."); 
    } 

    // make sure the directory we plan to store the recording in exists 
    File directory = new File(path).getParentFile(); 
    System.out.println("start() directory > " + directory); 
    if (!directory.exists() && !directory.mkdirs()) { 
     throw new IOException("Path to file could not be created."); 
    } 



    recorder.setAudioSource(MediaRecorder.AudioSource.MIC); // Sets the 
    // audio source 
    // to be used 
    // for recording 



    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // Sets 
    // the 
    // format 
    // of 
    // the 
    // output 
    // file 
    // produced 
    // during 
    // recording. 
    // 5 Minutes = 300000 Milliseconds 

    recorder.setMaxDuration(300000); // Sets the maximum duration (in ms) of 
    // the recording session 



    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // Sets the 
    // audio 
    // encoder 
    // to be 
    // used for 
    // recording. 

    recorder.setOutputFile(path); // Sets the path of the output file to be 
    // produced. 
    recorder.prepare(); // Prepares the recorder to begin capturing and 
    // encoding data. 
    recorder.start(); // Recording is now started 

}

+0

谢谢詹妮弗,我曾尝试使用媒体录像机录制视频,但它在三星Galaxy等一些平台上不稳定。我希望有一种方法可以增加最大时间,因为我需要action_capture意图使用的所有内容。有任何想法吗? – user875139

+1

你试过了:android.provider.MediaStore.EXTRA_DURATION_LIMIT对吗? – jennifer

+0

是的,我试过这个intent.putExtra(“android.intent.extra.durationLimit”,60000);.依然没有。 – user875139

15
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
intent.putExtra("android.intent.extra.durationLimit", 30000); 
intent.putExtra("EXTRA_VIDEO_QUALITY", 0); 
startActivityForResult(intent, ActivityRequests.REQUEST_TAKE_VIDEO); 

此代码的工作以及对API 2.2,但持续时间限制不会对API 2.1

android.intent.extra.durationLimitAPI Level 8,介绍所以它的工作不幸的是,在Eclair和更早的时候不可用。一些设备制造商可能会采用专有方式来设置旧设备的最长持续时间,这就解释了为什么您在某些Pre-Froyo应用程序中看到了这一点。

+0

通过查看Android资源网站上灰色栏的右侧,您可以看到每个变量的API级别。例如,请参阅此变量(以及它的API级别):http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_DURATION_LIMIT – jennifer

+0

请检查此链接:http://www.netmite.com /android/mydroid/donut/packages/apps/Camera/src/com/android/camera/VideoCamera.java ..它会对你有用 – jennifer

+1

我在这里得到了错误的ActivityRequests? –

30

实际上,MediaStore.EXTRA_DURATION_LIMIT提供的时间为,不是以毫秒为单位! 所以,你只需要改变你的价值从60000到60;) Android Documentation

3

使用此,这里60是第二 代码: intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60);

6

对于30秒的时间,试试这个代码。

intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30); 
相关问题