Android通话录音

l13615556434 2011-09-23 01:17:27
1、Android怎么实现通话录音的,代码能给看看么?
2、网上说上行和下行的音频录不了,能录的也是混合音的
3、ALSA能不能支持单向录音,也就是单独的录来电的声音和自己说话的MIC的声音的,具体的配置是怎么配的呢。

很迷惑
...全文
435 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
l13615556434 2011-09-26
  • 打赏
  • 举报
回复
那这样好了,怎么实现ALSA的单声道录音,就是只录制左声道或者只录制右声道的
念茜 2011-09-26
  • 打赏
  • 举报
回复
没有看到任何关于单向录音的资料,Mic的不少


package irdc.ex07_11;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class EX07_11 extends Activity
{
private ImageButton myButton1;
private ImageButton myButton2;
private ImageButton myButton3;
private ImageButton myButton4;
private ListView myListView1;
private String strTempFile = "ex07_11_";
private File myRecAudioFile;
private File myRecAudioDir;
private File myPlayFile;
private MediaRecorder mMediaRecorder01;

private ArrayList<String> recordFiles;
private ArrayAdapter<String> adapter;
private TextView myTextView1;
private boolean sdCardExit;
private boolean isStopRecord;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

myButton1 = (ImageButton) findViewById(R.id.ImageButton01);
myButton2 = (ImageButton) findViewById(R.id.ImageButton02);
myButton3 = (ImageButton) findViewById(R.id.ImageButton03);
myButton4 = (ImageButton) findViewById(R.id.ImageButton04);
myListView1 = (ListView) findViewById(R.id.ListView01);
myTextView1 = (TextView) findViewById(R.id.TextView01);
myButton2.setEnabled(false);
myButton3.setEnabled(false);
myButton4.setEnabled(false);

sdCardExit = Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
if (sdCardExit)
myRecAudioDir = Environment.getExternalStorageDirectory();


getRecordFiles();

adapter = new ArrayAdapter<String>(this,
R.layout.my_simple_list_item, recordFiles);

myListView1.setAdapter(adapter);


myButton1.setOnClickListener(new ImageButton.OnClickListener()
{

@Override
public void onClick(View arg0)
{
try
{
if (!sdCardExit)
{
Toast.makeText(EX07_11.this, "Ω–¥°§JSD Card",
Toast.LENGTH_LONG).show();
return;
}


myRecAudioFile = File.createTempFile(strTempFile, ".amr",
myRecAudioDir);

mMediaRecorder01 = new MediaRecorder();

mMediaRecorder01
.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder01
.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mMediaRecorder01
.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);

mMediaRecorder01.setOutputFile(myRecAudioFile
.getAbsolutePath());

mMediaRecorder01.prepare();

mMediaRecorder01.start();

myTextView1.setText("ø˝≠µ§§");

myButton2.setEnabled(true);
myButton3.setEnabled(false);
myButton4.setEnabled(false);

isStopRecord = false;

} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});

myButton2.setOnClickListener(new ImageButton.OnClickListener()
{

@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
if (myRecAudioFile != null)
{

mMediaRecorder01.stop();

adapter.add(myRecAudioFile.getName());
mMediaRecorder01.release();
mMediaRecorder01 = null;
myTextView1.setText("∞±§Ó°G" + myRecAudioFile.getName());

myButton2.setEnabled(false);

isStopRecord = true;
}
}
});

myButton3.setOnClickListener(new ImageButton.OnClickListener()
{

@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
if (myPlayFile != null && myPlayFile.exists())
{

openFile(myPlayFile);
}

}
});

myButton4.setOnClickListener(new ImageButton.OnClickListener()
{

@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
if (myPlayFile != null)
{

adapter.remove(myPlayFile.getName());

if (myPlayFile.exists())
myPlayFile.delete();
myTextView1.setText("ßπ¶®ßR∞£");
}

}
});

myListView1
.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3)
{

myButton3.setEnabled(true);
myButton4.setEnabled(true);

myPlayFile = new File(myRecAudioDir.getAbsolutePath()
+ File.separator
+ ((CheckedTextView) arg1).getText());
myTextView1.setText("ßAøÔ™∫¨O°G"
+ ((CheckedTextView) arg1).getText());
}
});

}

@Override
protected void onStop()
{
if (mMediaRecorder01 != null && !isStopRecord)
{

mMediaRecorder01.stop();
mMediaRecorder01.release();
mMediaRecorder01 = null;
}
super.onStop();
}

private void getRecordFiles()
{
recordFiles = new ArrayList<String>();
if (sdCardExit)
{
File files[] = myRecAudioDir.listFiles();
if (files != null)
{

for (int i = 0; i < files.length; i++)
{
if (files[i].getName().indexOf(".") >= 0)
{

String fileS = files[i].getName().substring(
files[i].getName().indexOf("."));
if (fileS.toLowerCase().equals(".amr"))
recordFiles.add(files[i].getName());

}
}
}
}
}


private void openFile(File f)
{
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);

String type = getMIMEType(f);
intent.setDataAndType(Uri.fromFile(f), type);
startActivity(intent);
}

private String getMIMEType(File f)
{
String end = f.getName().substring(
f.getName().lastIndexOf(".") + 1, f.getName().length())
.toLowerCase();
String type = "";
if (end.equals("mp3") || end.equals("aac") || end.equals("aac")
|| end.equals("amr") || end.equals("mpeg")
|| end.equals("mp4"))
{
type = "audio";
} else if (end.equals("jpg") || end.equals("gif")
|| end.equals("png") || end.equals("jpeg"))
{
type = "image";
} else
{
type = "*";
}
type += "/*";
return type;
}
}
l13615556434 2011-09-26
  • 打赏
  • 举报
回复
怎么没有人回答啊,能不能单独的录制左声道或者右声道的声音啊。

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧