2011-10-31 12 views
20

Estoy usando el android.provider.MediaStore.ACTION_VIDEO_CAPTURE. Me preguntaba si hay una manera de cambiar el tiempo máximo permitido por grabación. INTENTÉ AGREGAR Intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60000);//max of 60 seconds pero continúa registrando pase. Gracias por adelantado.¿Es posible establecer un tiempo máximo permitido para la grabación de Android con intención?

+3

Tenga en cuenta que MediaStore.EXTRA_DURATION_LIMIT se da en segundos, no en milisegundos. Sin embargo, solo funciona para dispositivos post-2.0. – user953768

Respuesta

2

Uso 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

Gracias Jennifer, he intentado usar el grabador de medios para grabar videos, pero es inestable en algunas plataformas como Samsung Galaxy. Esperaba que hubiera una manera de agregar un tiempo máximo porque necesito todo lo que usa el intento action_capture. ¿Algunas ideas? – user875139

+1

probaste: android.provider.MediaStore.EXTRA_DURATION_LIMIT ¿verdad? – jennifer

+0

Sí, lo intenté y este intent.putExtra ("android.intent.extra.durationLimit", 60000) ;. Aún nada. – 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); 

Este código funciona bien en la API 2.2, pero el límite de duración no funciona en API 2.1

android.intent.extra.durationLimit se introdujo en API Level 8, por lo que es no disponible en Eclair y antes, desafortunadamente. Algunos fabricantes de dispositivos pueden tener una forma patentada de establecer la duración máxima en dispositivos más antiguos, lo que explica por qué lo ha visto funcionar en algunas aplicaciones anteriores a Froyo.

+0

puede ver el nivel de API en el que se introduce cada variable mirando al lado derecho de la barra gris en el sitio de recursos de Android. Por ejemplo, vea esta variable (y su nivel de API) aquí: http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_DURATION_LIMIT – jennifer

+0

Consulte también este enlace: http://www.netmite.com /android/mydroid/donut/packages/apps/Camera/src/com/android/camera/VideoCamera.java .. Te será útil – jennifer

+1

Recibí el error ActivityRequests aquí? –

30

En realidad, MediaStore.EXTRA_DURATION_LIMIT proporcionar tiempo en segundos, NO en milisegundos! lo que sólo tiene que cambiar su valor a partir de 60000 a 60;) Android Documentation

3

Uso esto, aquí es 60 segundos Código: intent.putExtra (MediaStore.EXTRA_DURATION_LIMIT, 60);

6

Durante 30 segundos, pruebe este código.

intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30); 
Cuestiones relacionadas