Record录音简介

本文档介绍了如何将Android源码中的Record模块导入Eclipse,并详细说明了Record应用在模拟器与手机上的区别。在模拟器上由于特定异常无法录音,而在手机上可以正常工作。建议设置录音格式为.3GP以确保兼容性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android源码中Record应用相对来说在模块中是比较简单的。文章之前,我把自己如何把源码导入Eclipse的过程写了一篇文档。

文档地址:http://blog.youkuaiyun.com/easy_gemini/article/details/8210934

在Eclipse中跑出来的Record界面:

这里需要强调的是,在模拟器中是不能录音的,手机上是可以的。这是因为

// Handle RuntimeException ifthe recording couldn't start

        try {

       

            mRecorder.start();     //为何模拟器录音不了,因为这个函数在运行时候抛出异常,执行了setError(INTERNAL_ERROR);

           

        } catch (RuntimeException exception) {

            AudioManager audioMngr =(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);

            boolean isInCall = audioMngr.getMode()== AudioManager.MODE_IN_CALL;

            if (isInCall) {

                setError(IN_CALL_RECORD_ERROR);

            } else {

             

                setError(INTERNAL_ERROR);

           }

根据调试之后确定在模拟器中的mRecorder.start();抛出了异常,走的是setError(INTERNAL_ERROR);

会提示。

进入start()方法后可以看到里面是库文件提供的方法   

/**

     * Begins capturing and encoding data tothe file specified with

     * setOutputFile(). Call this afterprepare().

     *

     * <p>Since API level 13, if applications set acamera via

     * {@link #setCamera(Camera)}, the apps canuse the camera after this method

     * call. The apps do not need to lock thecamera again. However, if this

     * method fails, the apps should still lockthe camera back. The apps should

     * not start another recording sessionduring recording.

     *

     * @throws IllegalStateException if itis called before

     * prepare().

     */

public native void start() throws IllegalStateException;

 

 在此解释下不少朋友问我,为何模拟器不可以运行的问题,手机上是没有问题的,我自己尝试过。请把录音类型设置为.3GP,因为有些手机可能对其他格式支持不是特别好。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值