MediaRecorder崩溃时记录的第二个音频剪辑 [英] MediaRecorder crashes when record a second audio clip

查看:206
本文介绍了MediaRecorder崩溃时记录的第二个音频剪辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想录制音频剪辑MediaRecorder,但我不断收到这些错误在我的logcat当我开始,停止和重新启动;该活动将也接近:

 信息/ DEBUG(1285):*** *** *** *** *** *** *** *** *** *** * ** *** *** *** *** ***
信息/ DEBUG(1285):建立指纹:LGE / thunderg / thunderg / thunderg:2.2.1 / FRG83 / eng.nikech.choi.20110126.134422:用户/释放键
信息/ DEBUG(1285):11(SIGSEGV),故障地址00000010
信息/ DEBUG(1285):R0,R1 00000000 00000000 R2 R3 a930cc98 00000001
......
信息/ DEBUG(1285):#00件00033c28 /system/lib/libmedia.so
信息/ DEBUG(1285):#01件0000780e /system/lib/libmedia_jni.so
......
信息/ DEBUG(1285):code左右邮编:
信息/ DEBUG(1285):a9033c08 2001e001 1c1861a0 46c0bd70 00029a58
......
信息/ DEBUG(1285):code左右LR:
信息/ DEBUG(1285):a93077f0 f7ffb510 bd10ffcf b082b570 ae011c05
......
信息/ DEBUG(1285):堆栈:
信息/ DEBUG(1285):bef054d0 00000001
......

这是音频剪辑被记录下来,可以在电脑上播放,但如果我想记录一个又一个,上面的情况发生。我已经要求准许在清单:

 <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E>< /使用许可权>
<使用许可权的android:NAME =android.permission.RECORD_AUDIO>< /使用许可权>

我使用本麦肯这个code:

 进口的java.io.File;
进口java.io.IOException异常;进口android.media.MediaRecorder;
进口android.os.Environment;/ **
 * @author&下; A HREF =htt​​p://www.benmccann.com>本麦肯&下; / A>
 * /公共类AudioRecorder {  最后MediaRecorder记录=新MediaRecorder();
  最后弦乐路径;  / **
   *创建在给定的路径中的新录音(相对于SD卡的根目录)。
   * /
  公共AudioRecorder(字符串路径){
    this.path = sanitizePath(路径);
  }  私人字符串sanitizePath(字符串路径){
    如果(!path.startsWith(/)){
      路径=/+路径;
    }
    如果(!path.contains(。)){
      路径+ =名为.3gp;
    }
    返回Environment.getExternalStorageDirectory()getAbsolutePath()+路径。
  }  / **
   *开始一个新的记录。
   * /
  公共无效的start()抛出IOException
    字符串状态= android.os.Environment.getExternalStorageState();
    如果(!state.equals(android.os.Environment.MEDIA_MOUNTED)){
        抛出新IOException异常(SD卡未安装它。+状态+。);
    }    //确保目录,我们计划存储在记录存在
    文件目录=新的文件(路径).getParentFile();
    如果(directory.exists()及!&放大器;!directory.mkdirs()){
      抛出新IOException异常(路径文件无法被创建。);
    }    recorder.reset();
    的System.out.println(重置);
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    的System.out.println(setAudioSource);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    的System.out.println(setOutputFormat);
    recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
    的System.out.println(setAudioEn codeR);
    recorder.setOutputFile(路径);
    的System.out.println(setOutputFile);
    。录音机prepare();
    的System.out.println(prepare);
    recorder.start();
    的System.out.println(开始);
  }  / **
   *停止了已经previously开始录音。
   * /
  公共无效停止()抛出IOException
    recorder.stop();
    的System.out.println(停止);
    recorder.release();
    的System.out.println(释放);
  }}

我的code:

 进口java.io.IOException异常;进口android.app.Activity;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;
进口android.widget.Toast;公共类测试活动扩展了活动实现OnClickListener {    私人最终字符串标记= TestActivity.class.getSimpleName();    按钮startRecord用于;
    按钮STO precord;
    布尔recordStarted = FALSE;
    私有静态字符串文件名=/Recordings/event.3gp;
    AudioRecorder audioRecorder;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.record);        startRecord用于=(按钮)findViewById(R.id.buttonStartRecord);
        STO precord =(按钮)findViewById(R.id.buttonSto precord);        startRecord.setOnClickListener(本);
        STO precord.setOnClickListener(本);
        audioRecorder =新AudioRecorder(文件名);
    }    @覆盖
    保护无效onResume(){
        super.onResume();
        Log.d(TAG,恢复);
    }    @覆盖
    保护无效的onPause(){
    super.onPause();
    Log.d(TAG,暂停);
    }    @覆盖
    公共无效的onClick(视图v){
        如果(V == startRecord用于){
            尝试{
                audioRecorder.start();
                Toast.makeText(这一点,R.string.msgRecordSuccessful,
                    Toast.LENGTH_SHORT).show();
                recordStarted = TRUE;
                Log.e(TAG,的String.format(记录:%S,recordStarted));
            }赶上(IOException异常五){
                e.printStackTrace();
                Toast.makeText(这一点,R.string.msgRecordFail,Toast.LENGTH_SHORT).show();
            }
        }否则如果(V == STO precord){
            如果(recordStarted ==真){
                尝试{
                    audioRecorder.stop();
                    recordStarted = FALSE;
                    Log.e(TAG,的String.format(记录:%S,recordStarted));
                }赶上(IOException异常五){
                    e.printStackTrace();
                }
            }其他{
                Toast.makeText(这一点,R.string.msgNotRecording,Toast.LENGTH_SHORT).show();
            }
        }
    } //结束的onClick}

XML:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直的android:layout_width =match_parent
    机器人:layout_height =match_parent>
    <按钮的android:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT机器人:文本=开始
        机器人:ID =@ + ID / buttonStartRecord>< /按钮>
    <按钮的android:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / buttonSto precord
        机器人:文字=停止>< /按钮>< / LinearLayout中>

字符串:

 <字符串名称=msgReset>被重置LT; /串>
<字符串名称=msgSetAudioSource> setAudioSource< /串>
<字符串名称=msgSetOutputFormat> setOutputFormat< /串>
<字符串名称=msgSetAudioEn codeR> setAudioEn $ C $为CR /串>
<字符串名称=msgSetOutputFile> setOutputFile< /串>
<字符串名称=味精prepare> prepare< /串>
<字符串名称=msgStart>启动< /串>

我没有大量的编程经验,我不知道这意味着什么或如何甚至搜索在谷歌这个问题......如果任何人都可以在这将是非常好的一个大方向点我:D

感谢您!!

------------更新---------------

@添
从logcat的调试块后面的几行:

 信息/ ActivityManager(1362):进程com.bcit.chairlogger(PID 26461)已经死亡。
信息/窗口管理器(1362):WIN死亡:窗口{44f04e20 com.bcit.chairlogger / com.bcit.chairlogger.TestActivity暂停= FALSE}
信息/ ActivityManager(1362):显示活动com.bcit.chairlogger / .TestActivity:106629毫秒(共106629毫秒)
信息/ usagestats机(1362):com.lge.launcher意外的简历,同时已在com.bcit.chairlogger恢复
WARN / Flex的(1456):的getString FLEX_OPERATOR_ code TLS
WARN / Flex的(1456):的getString FLEX_OPERATOR_ code TLS
信息/#LGIME(1442):#### onStartInput:重新启动=假,fieldId = -1
WARN / InputManagerService(1362):GOT的RemoteException发送SETACTIVE(假)的通知为PID 26461 UID 10071


解决方案

我有同样的错误,解决方案,它为我的工作, MediaRecorder记录=新MediaRecorder(); 在启动的开始()(Android中 几个录音)

I am trying to record audio clips with MediaRecorder, but I keep getting these errors in my Logcat when I start, stop, and start again; the activity would also close:

INFO/DEBUG(1285): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
INFO/DEBUG(1285): Build fingerprint: 'LGE/thunderg/thunderg/thunderg:2.2.1/FRG83/eng.nikech.choi.20110126.134422:user/release-keys'
INFO/DEBUG(1285): signal 11 (SIGSEGV), fault addr 00000010
INFO/DEBUG(1285):  r0 00000000  r1 00000000  r2 a930cc98  r3 00000001
……
INFO/DEBUG(1285):          #00  pc 00033c28  /system/lib/libmedia.so
INFO/DEBUG(1285):          #01  pc 0000780e  /system/lib/libmedia_jni.so
……
INFO/DEBUG(1285): code around pc:
INFO/DEBUG(1285): a9033c08 2001e001 1c1861a0 46c0bd70 00029a58 
……
INFO/DEBUG(1285): code around lr:
INFO/DEBUG(1285): a93077f0 f7ffb510 bd10ffcf b082b570 ae011c05 
……
INFO/DEBUG(1285): stack:
INFO/DEBUG(1285):     bef054d0  00000001 
……

An audio clip is recorded and can be played on the computer, but if I want to record another one, the above happens. I have already asked for permission in the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>

I used this code from Ben McCann:

import java.io.File;
import java.io.IOException;

import android.media.MediaRecorder;
import android.os.Environment;

/**
 * @author <a href="http://www.benmccann.com">Ben McCann</a>
 */

public class AudioRecorder {

  final MediaRecorder recorder = new MediaRecorder();
  final String path;

  /**
   * Creates a new audio recording at the given path (relative to root of SD card).
   */
  public AudioRecorder(String path) {
    this.path = sanitizePath(path);
  }

  private String sanitizePath(String path) {
    if (!path.startsWith("/")) {
      path = "/" + path;
    }
    if (!path.contains(".")) {
      path += ".3gp";
    }
    return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
  }

  /**
   * Starts a new recording.
   */
  public void start() throws IOException {
    String state = android.os.Environment.getExternalStorageState();
    if(!state.equals(android.os.Environment.MEDIA_MOUNTED))  {
        throw new IOException("SD Card is not mounted.  It is " + state + ".");
    }

    // make sure the directory we plan to store the recording in exists
    File directory = new File(path).getParentFile();
    if (!directory.exists() && !directory.mkdirs()) {
      throw new IOException("Path to file could not be created.");
    }

    recorder.reset();
    System.out.println("reset");
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    System.out.println("setAudioSource");
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    System.out.println("setOutputFormat");
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    System.out.println("setAudioEncoder");
    recorder.setOutputFile(path);
    System.out.println("setOutputFile");
    recorder.prepare();
    System.out.println("prepare");
    recorder.start();
    System.out.println("start");
  }

  /**
   * Stops a recording that has been previously started.
   */
  public void stop() throws IOException {
    recorder.stop();
    System.out.println("stopped");
    recorder.release();
    System.out.println("released");
  }

}

My code:

import java.io.IOException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class TestActivity extends Activity implements OnClickListener {

    private final String TAG = TestActivity.class.getSimpleName();

    Button startRecord;
    Button stopRecord;
    boolean recordStarted = false;
    private static String fileName = "/Recordings/event.3gp";
    AudioRecorder audioRecorder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.record);

        startRecord = (Button)findViewById(R.id.buttonStartRecord);
        stopRecord = (Button)findViewById(R.id.buttonStopRecord);

        startRecord.setOnClickListener(this);
        stopRecord.setOnClickListener(this);
        audioRecorder = new AudioRecorder(fileName);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "resumed");
    }

    @Override
    protected void onPause() {
    super.onPause();
    Log.d(TAG, "paused");
    }

    @Override
    public void onClick(View v) {
        if (v == startRecord){
            try {
                audioRecorder.start();
                Toast.makeText(this, R.string.msgRecordSuccessful,
                    Toast.LENGTH_SHORT).show();
                recordStarted = true;
                Log.e(TAG, String.format("recording: %s", recordStarted));
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(this, R.string.msgRecordFail, Toast.LENGTH_SHORT).show();
            }
        } else if (v == stopRecord){
            if (recordStarted == true) {
                try {
                    audioRecorder.stop();
                    recordStarted = false;
                    Log.e(TAG, String.format("recording: %s", recordStarted));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(this, R.string.msgNotRecording, Toast.LENGTH_SHORT).show();
            }
        }
    } // end onClick

}

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="start"
        android:id="@+id/buttonStartRecord"></Button>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/buttonStopRecord"
        android:text="Stop"></Button>

</LinearLayout>

Strings:

<string name="msgReset">reset</string>
<string name="msgSetAudioSource">setAudioSource</string>
<string name="msgSetOutputFormat">setOutputFormat</string>
<string name="msgSetAudioEncoder">setAudioEncoder</string>
<string name="msgSetOutputFile">setOutputFile</string>
<string name="msgPrepare">prepare</string>
<string name="msgStart">start</string>

I don't have a lot of programming experience and I have no idea what this means or how to even search for this problem in Google... if anybody can point me in a general direction that would be really nice :D

Thank you!!

------------ updates ---------------

@ Tim the few lines after the debug block from logcat:

INFO/ActivityManager(1362): Process com.bcit.chairlogger (pid 26461) has died.
INFO/WindowManager(1362): WIN DEATH: Window{44f04e20 com.bcit.chairlogger/com.bcit.chairlogger.TestActivity paused=false}
INFO/ActivityManager(1362): Displayed activity com.bcit.chairlogger/.TestActivity: 106629 ms (total 106629 ms)
INFO/UsageStats(1362): Unexpected resume of com.lge.launcher while already resumed in com.bcit.chairlogger
WARN/Flex(1456): getString FLEX_OPERATOR_CODE TLS
WARN/Flex(1456): getString FLEX_OPERATOR_CODE TLS
INFO/#LGIME(1442): #### onStartInput: restarting=false, fieldId=-1
WARN/InputManagerService(1362): Got RemoteException sending setActive(false) notification to pid 26461 uid 10071

解决方案

i had same error, solution that worked for me "And MediaRecorder recorder = new MediaRecorder(); at the beginning of start()" (Several audio recording in Android)

这篇关于MediaRecorder崩溃时记录的第二个音频剪辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆