Android視音頻錄製實現步驟(Android學習隨筆八)

來源:互聯網
上載者:User

 

Android對音頻視頻的錄製是通過MediaRecoer類來完成的。其實現步驟為:

 

a、產生MediaRecorder類對象,

 

MediaRecorder  recorder  =   new   MediaRecorder();

 

b、設定音頻視頻錄製來源,

 

recorder.setAudioSource(int audio_source); //設定音頻錄製來源 (MediaRecorder.AudioSource中查詢相應的音頻錄製來源常量)

 

或者,recorder.setVideoSource(int video_source);//設定視頻錄製來源 (MediaRecorder.VideoSource中查詢相應的視頻錄製來源常量)

c、設定在錄製過程中輸出檔案格式(這個步驟在recorder.prepare()之前),

 

recorder.setOutputFormate(int output_formate);//MediaRecorder.OutputFormate 中可查相應的檔案格式

 

d、設定音頻視頻的編碼方式,

 

recorder.setAudioEncoder(int audio_encoder);//設定音頻錄製編碼方式 (MediaRecorder.AudioEncoder中查詢相應的音頻編碼常量)

 

或者,recorder.setVideoEncoder(int video_encoder);//設定視頻錄製編碼方式 (MediaRecorder.VideoEncoder中查詢相應的視頻編碼常量)

 

e、設定輸出檔案儲存地址(這一步在orecorder.setOutputFormate()之後,在recorder.prepare()之前),recorder.setOutputFile(String path);

 

f、準備錄製機開始捕獲編碼資料,recorder.prepare();

 

g、正式開始捕獲編碼資料到指定的檔案,recorder.start();

 

以上步驟就是錄製視音訊方法。除以上方法還有幾個比較常用的方法,如 下:

 

recorder.stop();//停止錄製

 

recorder.reset();//重新啟動MediaRecorder對象再次錄製,並且, 還必須重新設定以上的資訊

 

recorder.release();//釋放掉與MediaRecorder對象相關的資源 (這個在我們停止錄製後,必須執行)

 

關於MediaRecorder對象狀態如下:(在我的Android相簿中的名字為mediarecorder_state_diagram圖片)

 



摘自 tianshijianbing1989的專欄

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.