Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android多媒體之音頻、視頻錄制MediaRecorder

Android多媒體之音頻、視頻錄制MediaRecorder

編輯:關於Android編程

概述:

MediaRecorder的狀態圖:
這裡寫圖片描述
Initial:初始狀態,當使用new()方法創建一個MediaRecorder對象或者調用了reset()方法時,該MediaRecZ喎?/kf/ware/vc/" target="_blank" class="keylink">vcmRlcrbUz/O0ptPaSW5pdGlhbNe0zKyho9Tayei2qMrTxrXUtLvy1d/S9Ma11LTWrrrzvavXqru7zqpJbml0aWFsaXplZNe0zKyho8HtzeKjrNTas/1SZWxlYXNlZNe0zKzN4rXExuTL/Ne0zKzNqLn9tffTw3Jlc2V0KCm3vbeotry/ydLUyrlNZWRpYVJlY29yZGVyvfjI67jD17TMrKGjPC9wPg0KPHA+SW5pdGlhbGl6ZWSjutLRs/XKvLuv17TMrKOsv8nS1M2ouf3U2kluaXRpYWzXtMystffTw3NldEF1ZGlvU291cmNlKCm78nNldFZpZGVvU291cmNlKCm3vbeovfjI67jD17TMrKGj1NrV4rj217TMrL/J0tTNqLn9c2V0T3V0cHV0Rm9ybWF0KCm3vbeoyejWw8rks/a48cq9o6y0y8qxTWVkaWFSZWNvcmRlctequ7vOqkRhdGFTb3VyY2VDb25maWd1cmVk17TMrKGjwe3N4qOszai5/XJlc2V0KCm3vbeovfjI60luaXRpYWzXtMysoaM8L3A+DQo8cD5EYXRhU291cmNlQ29uZmlndXJlZKO6yv2+3dS0xeTWw9e0zKyjrNXixtq85L/J0tTJ6LaoseDC67e9yr2hosrks/bOxLz+oaLGwcS70P3XqqGi1KTAwM/Uyr61yLXIoaO/ydLU1NpJbml0aWFsaXplZNe0zKzNqLn9c2V0T3V0cHV0Rm9ybWF0KCm3vbeovfjI67jD17TMrKGjwe3N4qOsv8nS1M2ouf1yZXNldCgpt723qLvYtb1Jbml0aWFs17TMrKOsu/LV382ouf1wcmVwYXJlKCm3vbeotb2071ByZXBhcmVk17TMrKGjPC9wPg0KPHA+UHJlcGFyZWSjur7N0PfXtMyso6zU2kRhdGFTb3VyY2VDb25maWd1cmVk17TMrM2ouf1wcmVwYXJlKCm3vbeovfjI67jD17TMrKGj1NrV4rj217TMrL/J0tTNqLn9c3RhcnQoKb34yOvCvNbG17TMrKGjwe3N4qOsv8nS1M2ouf1yZXNldCgpt723qLvYtb1Jbml0aWFsaXplZNe0zKyhozwvcD4NCjxwPlJlY29yZGluZ6O6wrzWxte0zKyjrL/J0tTU2lByZXBhcmVk17TMrM2ouf2199PDc3RhcnQoKbe9t6i9+MjruMPXtMysoaPB7c3io6zL/L/J0tTNqLn9c3RvcCgpt723qLvycmVzZXQoKbe9t6i72LW9SW5pdGlhbNe0zKyhozwvcD4NCjxwPlJlbGVhc2Vko7rKzbfF17TMrKOoudm3vc7EtbW4+LP2tcS0yr3Q1/ZJZGxlIHN0YXRlIL/Vz9DXtMyso6mjrL/J0tTNqLn91NpJbml0aWFs17TMrLX308NyZWxlYXNlKCm3vbeowLS9+Mjr1eK49te0zKyjrNXiyrG9q7vhys23xcv509C6zU1lZGlhUmVjb3JkZXK21M/zsPO2qLXE18rUtKGjPC9wPg0KPHA+RXJyb3KjurTtzvPXtMyso6y1sbTtzvO3osn6tcTKsbryvfjI69XiuPbXtMyso6zL/L/J0tTNqLn9cmVzZXQoKbe9t6i9+MjrSW5pdGlhbNe0zKyhozwvcD4NCjxwPszhyr6jutPrTWVkaWFQbGF5ZXLP4MvGyrnTw01lZGlhUmVjb3JkZXLCvNL0wrzP8cqx0OjSqtHPuPHX8crY17TMrM28y7XD99bQtcS6r8r9tffTw8/IuvPLs9Dyo6zU2rK7zay1xNe0zKy199PDsrvNrLXEuq/K/aOst/HU8rvhs/bP1tLss6OhozwvcD4NCjxoMiBpZD0="代碼">代碼:

開始錄制音頻:

mRecorder = new MediaRecorder();
                //Sets the audio source to be used for recording,設置音頻資源
                mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                //Sets the format of the output file produced during recording,設置輸出音頻的格式
                mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                //Sets the video encoder to be used for recording,設置音頻編碼格式
                mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                //Sets the path of the output file to be produced,設置音頻文件輸出路徑
                mRecorder.setOutputFile(Environment.getExternalStorageDirectory()  + /my_recorder.3gp);
                try {
                    //Prepares the recorder to begin capturing and encoding data
                    mRecorder.prepare();
                    //Begins capturing and encoding data to the file specified with setOutputFile()
                    mRecorder.start();
                } catch (IOException e) {
                    e.printStackTrace();
                }

停止錄制音頻

//Stops recording
                mRecorder.stop();
                //Restarts the MediaRecorder to its idle state
                mRecorder.reset();
                //Releases resources associated with this MediaRecorder object,釋放資源
                mRecorder.release();

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved