android本地錄音
A. 安卓手機錄音在哪裡打開
vivo手機點擊進入錄音機軟體,點擊下方的圓形按鈕,即可開始錄音;
在錄音過程中點擊「‖」按鈕可以暫停錄音,再次點擊可繼續錄音,點擊「✓」按鈕即可結束錄音並保存錄音文件。
B. 安卓手機的錄音存在哪個文件夾里
安卓手機的錄音存在Recordings(錄音文件)這個文件夾裡面,要找到這個文件夾可以嘗試以下操作:
1、打開文件管理;
C. 如何找到安卓手機的錄音功能
方法:在手機的實用工具中可以找到手機的錄音功能,以華為手機為例說明:
具體步驟如下:
1、在手機找到應用工具文件夾並點擊打開;
注意事項
不同安卓手機的錄音功能可能不在同一位置,部分手機可以在手機設置中打開錄音功能,相對應的錄音本地文件可以在手機存儲位置找到。
D. 安卓手機怎麼錄音
安卓手機錄音的方法:
1、以oppo a31手機為例,首先點擊桌面上的工具文件夾進入。
E. Android實現錄音功能
1 Android錄音需要聲明錄音許可權
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
2.錄音文件要寫到文件夾中,創建文件夾,在Application的onCreate方法中創建文件夾
@Override
public void onCreate() {
super.onCreate();
CrashHandler mCrashHandler = CrashHandler.getInstance();
mCrashHandler.init(getApplicationContext(), getClass());
initFile();
}
private void initFile() {
//錄音文件
File audioFile = new File(Constant.UrlAudio);
if (!audioFile.exists()) {
audioFile.mkdirs();
} else if (!audioFile.isDirectory()) {
audioFile.delete();
audioFile.mkdirs();
}
//拍攝圖片文件
File imageFile = new File(Constant.UrlImage);
if (!imageFile.exists()) {
imageFile.mkdirs();
} else if (!imageFile.isDirectory()) {
imageFile.delete();
imageFile.mkdirs();
}
}
Constant.UrlImage是個靜態的文件路徑
//錄音文件
public static String UrlAudio = FileUtil.getSdcardPathOnSys()+"/EhmFile/media/audio/";
3.在activity中開始錄音
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.media.MediaRecorder;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Locale;
public class Record2Activity extends AppCompatActivity {
// 錄音界面相關
Button btnStart;
Button btnStop;
TextView textTime;
// 錄音功能相關
MediaRecorder mMediaRecorder; // MediaRecorder 實例
boolean isRecording; // 錄音狀態
String fileName; // 錄音文件的名稱
String filePath; // 錄音文件存儲路徑
Thread timeThread; // 記錄錄音時長的線程
int timeCount; // 錄音時長 計數
final int TIME_COUNT = 0x101;
// 錄音文件存放目錄
final String audioSaveDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/audiodemo/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_record2);
btnStart = (Button) findViewById(R.id.btn_start);
btnStop = (Button) findViewById(R.id.btn_stop);
textTime = (TextView) findViewById(R.id.text_time);
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 開始錄音
btnStart.setEnabled(false);
btnStop.setEnabled(true);
startRecord();
isRecording = true;
// 初始化錄音時長記錄
timeThread = new Thread(new Runnable() {
@Override
public void run() {
countTime();
}
});
timeThread.start();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 停止錄音
btnStart.setEnabled(true);
btnStop.setEnabled(false);
stopRecord();
isRecording = false;
}
});
}
// 記錄錄音時長
private void countTime() {
while (isRecording) {
Log.d("mediaRe","正在錄音");
timeCount++;
Message msg = Message.obtain();
msg.what = TIME_COUNT;
msg.obj = timeCount;
myHandler.sendMessage(msg);
try {
timeThread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Log.d("mediaRec", "結束錄音");
timeCount = 0;
Message msg = Message.obtain();
msg.what = TIME_COUNT;
msg.obj = timeCount;
myHandler.sendMessage(msg);
}
/**
* 開始錄音 使用amr格式
* 錄音文件
*
* @return
*/
public void startRecord() {
// 開始錄音
/* ①Initial:實例化MediaRecorder對象 */
if (mMediaRecorder == null)
mMediaRecorder = new MediaRecorder();
try {
/* ②setAudioSource/setVedioSource */
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);// 設置麥克風
/*
* ②設置輸出文件的格式:THREE_GPP/MPEG-4/RAW_AMR/Default THREE_GPP(3gp格式
* ,H263視頻/ARM音頻編碼)、MPEG-4、RAW_AMR(只支持音頻且音頻編碼要求為AMR_NB)
*/
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
/* ②設置音頻文件的編碼:AAC/AMR_NB/AMR_MB/Default 聲音的(波形)的采樣 */
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
fileName = DateFormat.format("yyyyMMdd_HHmmss", Calendar.getInstance(Locale.CHINA)) + ".m4a";
//注意文件夾要創建之後才能使用
filePath = Constant.UrlAudio + fileName;
/* ③准備 */
mMediaRecorder.setOutputFile(filePath);
mMediaRecorder.prepare();
/* ④開始 */
mMediaRecorder.start();
} catch (IllegalStateException e) {
Log.i("mediaEr", "call startAmr(File mRecAudioFile) failed!" + e.getMessage());
} catch (IOException e) {
e.printStackTrace();
Log.i("mediaEr", "call startAmr(File mRecAudioFile) failed!" + e.getMessage());
}
}
/**
* 停止錄音
*/
public void stopRecord() {
//有一些網友反應在5.0以上在調用stop的時候會報錯,翻閱了一下谷歌文檔發現上面確實寫的有可能會報錯的情況,捕獲異常清理一下就行了,感謝大家反饋!
try {
mMediaRecorder.stop();
mMediaRecorder.release();
mMediaRecorder = null;
filePath = "";
} catch (RuntimeException e) {
Log.e("mediaR", e.toString());
mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
File file = new File(filePath);
if (file.exists())
file.delete();
filePath = "";
}
}
// 格式化 錄音時長為 秒
public static String FormatMiss(int miss) {
return "" + miss;
}
Handler myHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case TIME_COUNT:
int count = (int) msg.obj;
Log.d("meidaRe","count == " + count);
textTime.setText(FormatMiss(count));
break;
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
myHandler.removeCallbacksAndMessages(null);
}
}
布局文件很簡單
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Record2Activity">
<Button
android:id="@+id/btn_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="結束"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btn_start"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="開始"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_stop"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="11dp"
android:layout_marginTop="47dp"
android:text="時間"
app:layout_constraintStart_toStartOf="@+id/btn_start"
app:layout_constraintTop_toBottomOf="@+id/btn_start" />
</androidx.constraintlayout.widget.ConstraintLayout>
這樣就可以使用錄音功能了
F. 安卓系統手機的錄音存放在哪個文件夾
安卓系統手機的錄音存放在/sdcard/voiceRecoder目錄下,如果是中文系統的話還有可能是在/sdcard/錄音機裡面。
查找方法:在SD卡的目錄下找這兩個文件夾,錄制音頻文件就在裡面的。
1、點擊「錄音WAV文件」,開始錄音。錄音完成後,生成文件/sdcard/FinalAudio.wav
2、點擊「錄音AMR文件」,開始錄音。錄音完成後,生成文件/sdcard/FinalAudio.amr
3、點擊「停止錄音」,停止錄音,並顯示錄音輸出文件以及該文件大小。