0

我是android中的新手,我正在一个应用程序中工作,该应用程序在设备中收到电话时启动,并启动一个IntenService来使用媒体记录器记录通话。这是我的日志猫输出。

01-14 13:58:07.319: D/DEBUG(18180): <!>com.agicent.callrecorder.CallListener 26<!> 
OFFHOOK
01-14 13:58:07.319: E/AudioRecordTest(18180): 
<!>com.agicent.callrecorder.PhoneCallRecorderActivity 181<!> Recording Started
01-14 13:58:07.469: E/AudioRecordTest(18180): 
<!>com.agicent.callrecorder.PhoneCallRecorderActivity 181<!> Recording Started
01-14 13:58:07.499: E/MediaRecorder(18180): start failed: -1
01-14 13:58:07.509: W/dalvikvm(18180): threadid=9: thread exiting with uncaught 
exception (group=0x40018560)
01-14 13:58:07.509: E/AndroidRuntime(18180): FATAL EXCEPTION: 
IntentService[PhoneCallRecorderActivity]
01-14 13:58:07.509: E/AndroidRuntime(18180): java.lang.RuntimeException: start failed.
01-14 13:58:07.509: E/AndroidRuntime(18180):    at 
android.media.MediaRecorder.start(Native Method)
01-14 13:58:07.509: E/AndroidRuntime(18180):    atcom.agicent.callrecorder.PhoneCallRecorderActivity.startRecording(PhoneCallRecorderActivity.java:77)
01-14 13:58:07.509: E/AndroidRuntime(18180):    at com.agicent.callrecorder.PhoneCallRecorderActivity.onHandleIntent(PhoneCallRecorderActivity.java:182)
01-14 13:58:07.509: E/AndroidRuntime(18180):    at    android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
01-14 13:58:07.509: E/AndroidRuntime(18180):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 13:58:07.509: E/AndroidRuntime(18180):    at android.os.Looper.loop(Looper.java:123)
01-14 13:58:07.509: E/AndroidRuntime(18180):    at  android.os.HandlerThread.run(HandlerThread.java:60)
01-14 13:58:20.539: E/IncomingCall Recieved(18256):       <!>com.agicent.callrecorder.IncomingCallReciever 33<!> Broadcast Recieved
01-14 13:58:20.569: D/DEBUG(18256): <!>com.agicent.callrecorder.CallListener 22<!> IDLE

这是我的代码块

public class PhoneCallRecorderActivity extends IntentService {

private static final String LOG_TAG = "AudioRecordTest";
private static String mFileName = null;
//private RecordButton mRecordButton = null;
private MediaRecorder mRecorder = null;
//private PlayButton   mPlayButton = null;
private MediaPlayer   mPlayer = null;

private void startPlaying() {
    mPlayer = new MediaPlayer();
    try {
        mPlayer.setDataSource(mFileName);
        mPlayer.prepare();
        mPlayer.start();
    } catch (IOException e) {
        Log.e(LOG_TAG, "prepare() failed");
    }
}

private void stopPlaying() {
    mPlayer.release();
    mPlayer = null;
}

private void startRecording() {
    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(mFileName);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);


    try {
        mRecorder.prepare();
    } catch (IOException e) {
        Log.e(LOG_TAG, "prepare() failed");
    }

    mRecorder.start();
}

private void stopRecording() {
    mRecorder.stop();
    mRecorder.release();
    mRecorder = null;
}

public PhoneCallRecorderActivity() {
    super("PhoneCallRecorderActivity");
    mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
    mFileName += "/audiorecordtest.3gp";
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

@Override
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
Log.e(LOG_TAG, "Recording Started");
startRecording();
}
public void onDestroy() {

stopRecording();
Log.e(LOG_TAG, "Recording finidhed");

}
}

请建议我在哪里做错了。非常感谢您的时间。

4

1 回答 1

0

如果您要记录实际通话本身(本地语音和远程语音),这在 Android 中是不可能的,因为通话音频信息是在 Android 本身之外处理的。

于 2012-01-16T07:41:33.210 回答