Android多媒體錄製功能的實現方式介紹

來源:互聯網
上載者:User

Android手機作業系統是由Google推出的一款基於Linux平台的開源作業系統。深受廣大編程愛好者們的喜愛。在這裡我們將會為大家詳細介紹有關Android多媒體錄製的相關功能,包括錄音與錄影。

還是先看代碼,用一種最笨的方式實現了Android多媒體錄製中的錄音的功能:

  1. try {   
  2. String path = "/sdcard/recorder.amr";   
  3. MediaRecorder recorder = new MediaRecorder();   
  4. recorder.setAudioSource(MediaRecorder.AudioSource.MIC);   
  5. recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);   
  6. recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);   
  7. recorder.setOutputFile(path+name);   
  8. recorder.prepare();   
  9. recorder.start();   
  10. try {   
  11. Runnable.wait(10000);   
  12. } catch (Exception exp) {   
  13. exp.printStackTrace();   
  14. }   
  15. recorder.stop();   
  16. recorder.release();   
  17. } catch (IllegalStateException e) {   
  18. e.printStackTrace();   
  19. } catch (IOException e) {   
  20. e.printStackTrace();   
  21. }  

10秒鐘哦,等也得等,不等也得等,不用線程怎麼行。

Android多媒體錄製中的錄影就是Audio+Video,所以還要加點東西,看代碼:

  1. path = "/sdcard/v.3gp";   
  2. recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);   
  3. recorder.setAudioSource(MediaRecorder.AudioSource.MIC);   
  4. recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);   
  5. recorder.setVideoSize(176, 144);   
  6. recorder.setVideoFrameRate(15);   
  7. recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);   
  8. recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);   
  9. recorder.setOutputFile(path);  

Android多媒體錄製的相關功能的理論上是沒錯的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.