2011-10-31 10 views
20

Sto usando il android.provider.MediaStore.ACTION_VIDEO_CAPTURE. Mi stavo chiedendo se c'è un modo per cambiare il tempo massimo consentito per ogni registrazione. Ho provato ad aggiungere Intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60000);//max of 60 seconds ma continua la registrazione. Grazie in anticipo.È possibile impostare un tempo massimo consentito per la registrazione su Android utilizzando l'intento?

+3

Si prega di notare che MediaStore.EXTRA_DURATION_LIMIT è dato in secondi, non in millisecondi. Tuttavia, funziona solo con dispositivi post-2.0. – user953768

risposta

2

Usa 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

Grazie Jennifer, ho provato ad usare il registratore multimediale per registrare video ma è instabile su alcune piattaforme come Samsung Galaxy. Speravo che ci fosse un modo per aggiungere solo un tempo massimo perché ho bisogno di tutto ciò che usa l'intento action_capture. Qualche idea? – user875139

+1

hai provato: android.provider.MediaStore.EXTRA_DURATION_LIMIT giusto ?? – jennifer

+0

Sì, l'ho provato e questo intent.putExtra ("android.intent.extra.durationLimit", 60000) ;. Ancora niente. – 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); 

Questo codice funziona bene su API 2.2, ma il limite della durata non funziona su API 2.1

android.intent.extra.durationLimit è stato introdotto nel API Level 8, quindi è non disponibile in Eclair e in precedenza, sfortunatamente. Alcuni produttori di dispositivi possono disporre di un modo proprietario per impostare la durata massima su dispositivi precedenti, il che spiega il motivo per cui l'hai visto funzionare su alcune applicazioni pre-Froyo.

+0

è possibile visualizzare il livello API a cui ogni variabile viene introdotta guardando sul lato destro della barra grigia sul sito delle risorse Android. Ad esempio, vedi questa variabile (ed è il livello API) qui: http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_DURATION_LIMIT – jennifer

+0

Controlla anche questo link: http://www.netmite.com /android/mydroid/donut/packages/apps/Camera/src/com/android/camera/VideoCamera.java .. Sarà utile per voi – jennifer

+1

Ho ricevuto l'errore AttivitàRichieste qui? –

30

In realtà, MediaStore.EXTRA_DURATION_LIMIT fornire il tempo in secondi, NON in millisecondi! Quindi è solo bisogno di cambiare il vostro valore di 60.000-60;) Android Documentation

3

Utilizzare questo, qui 60 è seconda Codice: intent.putExtra (MediaStore.EXTRA_DURATION_LIMIT, 60);

6

Per 30 secondi, prova questo codice.

intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30); 
Problemi correlati