当前位置:首页 » 安卓系统 » 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>

这样就可以使用录音功能了

热点内容
Ftp打开文件是只读模式 发布:2025-02-09 07:40:55 浏览:504
androidlistview点击事件 发布:2025-02-09 07:25:52 浏览:171
targz解压缩 发布:2025-02-09 06:59:19 浏览:311
wpsphp 发布:2025-02-09 06:58:41 浏览:961
视易锋云系统如何架设辅助服务器 发布:2025-02-09 06:47:08 浏览:770
mysql备份脚本shell 发布:2025-02-09 06:46:33 浏览:15
腾讯云服务器怎样调整分辨率 发布:2025-02-09 06:46:30 浏览:369
php上一个页面 发布:2025-02-09 06:41:25 浏览:489
改装配置后不想重启怎么办 发布:2025-02-09 06:36:40 浏览:446
算法复杂度定义 发布:2025-02-09 06:30:46 浏览:587