當前位置:首頁 » 安卓系統 » android錄音與播放

android錄音與播放

發布時間: 2023-06-04 04:22:34

A. android的錄音和播放需要哪些許可權

清單文件裡面加上下面2種許可權
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

B. android中怎麼在通話中播放錄音

1.在手機開機界面點擊「撥號」按鈕。
2.在撥號界面撥電話號碼,接通電話。

3.在通話中,點擊右下角「三點」菜單鍵。

4.在彈出菜單中,點擊「開始錄制」。

5.在通話中,右上角有紅點標識就表示在錄音中。掛斷電話,錄音自動終止。錄音會自動保存。

C. android 軟體開發 怎麼實現錄音和放音,如果播放聲音,在模擬器上就能聽見播放的聲音嗎跪求,謝謝大家了

1、MediaRecorder錄音,MediaPlayer播放,使用的時候注意他們的生命周期。
2、模擬器上播放聲音是沒問題的,pc外放能聽的到
還有問題可以追問

D. Android 軟體開發中,如何選擇可用的揚聲器進行播放(或者麥克風進行錄音)

正常情況下,選擇音頻類型進行播放,或者選擇指定的input source 進行錄音後,系統會根據對應音頻類型和source類型進行分配對應的有效設備,所以如果系統有對應的設備內容,在播放和錄音的時候,系統會分配相應的 mic 和 speaker,因此不需要額外指定的

E. android開發中的錄音機上的播放和暫停按鈕是怎麼做出來的

那個其實是一個Button,先為你的Button設置一張背景圖,就是播放的那個三角形圖片。然後你點擊Button的時候變成另外一張圖片,就是暫停的那個圖片,具體是這樣的
boolean
isClicked
=
true;
Button.setOnClickListener(new
OnClickListener()
{
public
void
onClick(View
v)
{
if(hasFocus){
m_btnPlay.setImageResource(播放圖片);
video.pause();
}else{
m_btnPlay.setImageResource(暫停圖片);
video.start();
}
isClicked
=
!isClicked;
}
});
希望能幫到您

F. 如何找到安卓手機的錄音功能

方法:在手機的實用工具中可以找到手機的錄音功能,以華為手機為例說明:

具體步驟如下:

1、在手機找到應用工具文件夾並點擊打開;

注意事項

不同安卓手機的錄音功能可能不在同一位置,部分手機可以在手機設置中打開錄音功能,相對應的錄音本地文件可以在手機存儲位置找到。

G. 安卓手機的錄音怎麼播放不了怎麼辦

錄音文件能不能播放,主要看播放它的軟體,認不認識這種格式。
如果不能播放,那麼就是軟體不認識錄音文件的格式。可以下載別人播放軟體來試一試,一般的比較出名的視頻播放器,或者音樂軟體,應該都可以播放。

H. 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>

這樣就可以使用錄音功能了

熱點內容
python常用正則表達式 發布:2025-02-09 04:42:53 瀏覽:177
機器人編程培訓哪家好 發布:2025-02-09 04:37:44 瀏覽:307
上海怎麼學習java 發布:2025-02-09 04:26:39 瀏覽:22
erp系統搭建備用伺服器 發布:2025-02-09 04:07:38 瀏覽:945
戴爾伺服器在bios怎麼配置管理ip 發布:2025-02-09 04:01:53 瀏覽:550
小魚易連雲存儲 發布:2025-02-09 03:59:47 瀏覽:91
正在限制訪問 發布:2025-02-09 03:47:17 瀏覽:903
架設資料庫 發布:2025-02-09 03:41:29 瀏覽:966
imacpro哪個配置最好 發布:2025-02-09 03:32:29 瀏覽:253
用編程對話 發布:2025-02-09 03:23:43 瀏覽:89