2011-10-31 11 views
20

मैं android.provider.MediaStore.ACTION_VIDEO_CAPTURE का उपयोग कर रहा हूं। मैं सोच रहा था कि रिकॉर्डिंग की अनुमति अधिकतम समय बदलने का कोई तरीका है या नहीं। मैंने Intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60000);//max of 60 seconds जोड़ने का प्रयास किया लेकिन यह रिकॉर्डिंग पास जारी रखता है। अग्रिम में धन्यवाद।क्या इरादा का उपयोग करके एंड्रॉइड रिकॉर्डिंग के लिए अधिकतम समय निर्धारित करना संभव है?

+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

धन्यवाद जेनिफर, मैंने वीडियो रिकॉर्ड करने के लिए मीडिया रिकॉर्डर का उपयोग करने का प्रयास किया है, लेकिन सैमसंग गैलेक्सी जैसे कुछ प्लेटफॉर्म पर इसका अस्थिर है। मैं उम्मीद कर रहा था कि अधिकतम समय जोड़ने का एक तरीका था क्योंकि मुझे action_capture इरादे का उपयोग करने वाली हर चीज की आवश्यकता है। कोई विचार? – user875139

+1

आपने कोशिश की: android.provider.MediaStore.EXTRA_DURATION_LIMIT सही ?? – jennifer

+0

हाँ, मैंने कोशिश की और यह इरादा .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); 

इस कोड एपीआई 2.2 पर अच्छी तरह से काम करता है, लेकिन अवधि सीमा एपीआई 2,1

android.intent.extra.durationLimitAPI Level 8, में पेश किया गया था तो यह है पर काम नहीं करता एक्लेयर और पहले, दुर्भाग्य से उपलब्ध नहीं है। कुछ डिवाइस निर्माताओं के पास पुराने उपकरणों पर अधिकतम अवधि निर्धारित करने का एक मालिकाना तरीका हो सकता है, जो बताता है कि आपने इसे कुछ प्री-फ़्रायियो अनुप्रयोगों पर क्यों काम किया है।

+0

आप एपीआई स्तर देख सकते हैं जिस पर प्रत्येक चर को एंड्रॉइड संसाधन साइट पर ग्रे बार के दाईं ओर देखकर पेश किया जाता है। उदाहरण के लिए, इस चर (और इसका एपीआई स्तर) यहां देखें: 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

मुझे गतिविधि गतिविधि में त्रुटि मिली है? –

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); 
संबंधित मुद्दे

 संबंधित मुद्दे