使用可视化工具从手机(而不是微型)录制声音

时间:2015-07-22 18:28:00

标签: android audio

我尝试录制手机的声音。我的目标是在我的应用中启动媒体播放器, 我的应用程序在mediaplayer声音上添加了声音(带有soundpool)。但在这里我无法捕捉 声音媒体播放器通过我的应用程序。我有一个文件(“audiofile”),它是用大小创建的,如果我没记错的话,这是我按下图标的长度的函数,但是当我播放文件时,我什么都没有,没有声音。

我通过一个可视化工具,因为我知道通过mediarecord或audiorecord进行录制只允许录制到任何材料只有麦克风。

由于

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();
                }

0 个答案:

没有答案