Android 使用visualizer从手机(而不是micro)录制声音
我试着录下电话里的声音。我的目标是在我的应用程序中启动mediaplayer, 我的应用程序在mediaplayer声音中添加了声音(带有声音池)。但在这里我无法捕捉 声音媒体播放器通过我的应用程序。我有一个文件(“音频文件”),如果我没记错的话,它是我按下图标的长度的函数,但是当我播放这个文件时,我什么都没有,没有声音 我之所以使用可视化工具,是因为我知道mediarecord或audiorecord的录制只允许通过麦克风录制任何材料 谢谢Android 使用visualizer从手机(而不是micro)录制声音,android,audio,Android,Audio,我试着录下电话里的声音。我的目标是在我的应用程序中启动mediaplayer, 我的应用程序在mediaplayer声音中添加了声音(带有声音池)。但在这里我无法捕捉 声音媒体播放器通过我的应用程序。我有一个文件(“音频文件”),如果我没记错的话,它是我按下图标的长度的函数,但是当我播放这个文件时,我什么都没有,没有声音 我之所以使用可视化工具,是因为我知道mediarecord或audiorecord的录制只允许通过麦克风录制任何材料 谢谢 My code: public String fi
My code:
public String fichierrecord="";
private Button auriculaire=null;
public boolean beginning=true;
public Spinner selecti;
public byte[] mBytes=null;
public ByteArrayOutputStream buffer;
public Visualizer v;
@Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.relalayou);
selecti=(Spinner) findViewById(R.id.spinner13);
auriculaire=(Button) findViewById(R.id.oreille);
v=new Visualizer(0);
buffer=new ByteArrayOutputStream();
v.setEnabled(false);
v.setCaptureSize(65536);
Visualizer.OnDataCaptureListener c=new Visualizer.OnDataCaptureListener(){
@Override
public void onWaveFormDataCapture(Visualizer vv, byte[] wf, int sr){
mBytes= wf;
if (wf.length>-1){
buffer.write(wf,0,wf.length);}
}
@Override
public void onFftDataCapture(Visualizer vv, byte[] wf, int sr) {
} };
v.setDataCaptureListener(c,Visualizer.getMaxCaptureRate()/2,true,true);
auriculaire.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg) {
if (beginning==true){
Toast.makeText(MainActivity.this, "begin", Toast.LENGTH_LONG).show();
v.setEnabled(true); beginning=false;}
else {v.setEnabled(false);
try {
buffer.flush();
} catch (IOException e) {
}
mBytes = buffer.toByteArray();
try {
buffer.close();
} catch (IOException e) {
}
v.release();
File f = new File(Environment.getExternalStorageDirectory(), "audiofile.wav");
FileOutputStream fos;
try {
fos = new FileOutputStream(f);
fos.write(mBytes);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
Toast.makeText(MainActivity.this, "end", Toast.LENGTH_LONG).show();
}
}List<String> exem=new ArrayList<String>();
exem.add("notFile");
exem.add("file");
final ArrayAdapter<String> ada =new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,exem);
selecti.setAdapter(ada);
selecti.setSelection(0);
selectitonalite.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
if (selecti.getSelectedItemId()==){
Toast.makeText(MainActivity.this, "Select the audio file (.mp3,.mp4,.m4a,.wav,.3gp,.ogg,.mkv,.mid,.xmf,.mxmf,.rttt1,.rtx,.ota,.imy)" +
"on which you want to play", Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this, "Select the audio file (.mp3,.mp4,.m4a,.wav,.3gp,.ogg,.mkv,.mid,.xmf,.mxmf,.rttt1,.rtx,.ota,.imy)" +
"on which you want to play", Toast.LENGTH_LONG).show();
File mPath = new File(Environment.getExternalStorageDirectory() + "//DIR//");
FileDialog fileDialog = new FileDialog(MainActivity.this, mPath);
fileDialog.setFileEndsWith(".mp3",".mp4",".m4a",".wav",".3gp",".ogg",".mkv",".mid",".xmf",".mxmf",".rttt1",".rtx",".ota",".imy");//,);
fileDialog.addFileListener(new FileDialog.FileSelectedListener() {
public void fileSelected(File file) {
File mmFichier = new File(fichierrecord);
if (mmFichier.exists()) {
MediaPlayer m= new MediaPlayer();try{m.setDataSource(fichierrecord);m.prepare();}catch(IOException e){};
MediaPlayer.create(getApplicationContext(), Uri.fromFile(mmFichier));
m.setVolume(1f,1f);
m.start();
file.toString());
}}
});
fileDialog.showDialog();
}
我的代码:
公共字符串fichierrecord=“”;
私有按钮auriculaire=null;
公共布尔开头=true;
公共微调器选择;
公共字节[]MB=null;
公共ByteArrayOutputStream缓冲区;
公共可视化工具v;
@凌驾
创建时受保护的void(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
setContentView(R.layout.relalayou);
selecti=(微调器)findViewById(R.id.spinner13);
耳廓=(按钮)findViewById(R.id.oreille);
v=新的可视化工具(0);
buffer=newbytearrayoutputstream();
v、 setEnabled(假);
v、 setCaptureSize(65536);
Visualizer.OnDataCaptureListener c=新的Visualizer.OnDataCaptureListener(){
@凌驾
公共void onWaveFormDataCapture(可视化工具vv,字节[]wf,int sr){
mBytes=wf;
如果(wf.长度>-1){
buffer.write(wf,0,wf.length);}
}
@凌驾
public void onFftDataCapture(可视化工具vv,字节[]wf,int sr){
} };
v、 setDataCaptureListener(c,Visualizer.getMaxCaptureRate()/2,true,true);
auriculaire.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图参数){
如果(开始==真){
Toast.makeText(MainActivity.this,“begin”,Toast.LENGTH_LONG.show();
v、 setEnabled(true);开始=false;}
else{v.setEnabled(false);
试一试{
buffer.flush();
}捕获(IOE异常){
}
mBytes=buffer.toByteArray();
试一试{
buffer.close();
}捕获(IOE异常){
}
v、 释放();
文件f=新文件(Environment.getExternalStorageDirectory(),“audiofile.wav”);
文件输出流;
试一试{
fos=新文件输出流(f);
fos.写入(兆字节);
fos.flush();
fos.close();
}catch(filenotfounde异常){
}捕获(IOE异常){
}
Toast.makeText(MainActivity.this,“end”,Toast.LENGTH_LONG.show();
}
}List exem=new ArrayList();
附件。添加(“notFile”);
exem.add(“文件”);
final ArrayAdapter ada=新的ArrayAdapter(这是android.R.layout.simple\u list\u item\u 1,exem);
选择i.setAdapter(ada);
selecti.setSelection(0);
selectitonalite.setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共视图(AdapterView arg0、视图arg1、,
整数arg2,长arg3){
如果(selecti.getSelectedItemId()=){
makeText(MainActivity.this,“选择音频文件(.mp3、.mp4、.m4a、.wav、.3gp、.ogg、.mkv、.mid、.xmf、.mxmf、.rttt1、.rtx、.ota、.imy)”+
“你想在上面玩”,Toast.LENGTH_LONG.show();
makeText(MainActivity.this,“选择音频文件(.mp3、.mp4、.m4a、.wav、.3gp、.ogg、.mkv、.mid、.xmf、.mxmf、.rttt1、.rtx、.ota、.imy)”+
“你想在上面玩”,Toast.LENGTH_LONG.show();
File mPath=新文件(Environment.getExternalStorageDirectory()+“///DIR//”);
FileDialog FileDialog=新建FileDialog(MainActivity.this,mPath);
fileDialog.setFileEndsWith(“.mp3”、“.mp4”、“.m4a”、“.wav”、“.3gp”、“.ogg”、“.mkv”、“.mid”、“.xmf”、“.mxmf”、“.rttt1”、“.rtx”、“.ota”、“.imy”);/,);
fileDialog.addFileListener(新建fileDialog.FileSelectedListener(){
已选择公共无效文件(文件){
文件mmFichier=新文件(fichierrecord);
如果(mmFichier.exists()){
MediaPlayer m=newmediaplayer();尝试{m.setDataSource(fichierrecord);m.prepare();}catch(IOException e){};
create(getApplicationContext(),Uri.fromFile(mmFichier));
m、 设置音量(1f,1f);
m、 start();
file.toString());
}}
});
fileDialog.showDialog();
}
(不是micro)
…哪一个micro?麦克风大概是。无论如何,文件不会仅仅因为你命名为.wav
。此外,除非你已经意识到这一点,可视化工具将为你提供非常低质量的音频,因为它的目的只是为了捕获音频以实现可视化。没有办法记录联合国降级的系统音频输出(AFAIK)。是的,我听说你可以在重新编译后用“不同的sdk”之类的东西录制输出。但是visualizer是一个(小的)轻微记录的可能性。我想尝试至少这种可能性。但是我关于这个主题的代码没有记录任何东西,我在关于visualizer的教程中找到了它,但它不起作用。我不理解这个代码的问题(不是micro)
…哪一个micro?麦克风大概是。无论如何,文件不会仅仅因为你命名为.wav
。此外,除非你已经意识到这一点,可视化工具将为你提供非常低质量的音频,因为它的目的只是为了捕获音频以实现可视化。没有办法记录联合国降级系统音频输出(AFAIK)。是的,我听说你可以用“不同的sdk”之类的东西录制输出