Android商店使用输入文本记录的音频? [英] Android store recorded audio using input text?

查看:132
本文介绍了Android商店使用输入文本记录的音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有记录并存储在SD卡音频的应用程序。它记录并在正确的地方保​​存,但其保存为android.widget.EditText@random号。我是用一个EditText来获取文件名。

有谁知道我可以让用户输入一些文字,并保存文件作为。我以为我到的东西与下面的code,但没有...

  {尝试
                    //设置用户输入的文件名
                    字符串文件名= getInput.toString();
                    //设置存储目录SD卡
                    文件storageDir =新的文件(Environment.getExternalStorageDirectory(),音频);
                    storageDir.mkdir();
                    Log.d(APP_TAG,存储目录设置为+ storageDir);                    OUTFILE = File.createTempFile(文件名,名为.3gp,storageDir);
                    //显示文件名
                    的System.out.println(文件是:+ outfile.getAbsolutePath());                    //开始记录
                    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                    recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
                    recorder.setOutputFile(outfile.getAbsolutePath());                }赶上(IOException异常五){
                    Log.w(APP_TAG,文件无法访问,E);
                }赶上(抛出:IllegalArgumentException五){
                    Log.w(APP_TAG,非法的说法,E);
                }赶上(IllegalStateException异常五){
                    Log.w(APP_TAG,非法状态,呼叫复位/恢复,E);
                }
                startRecord用于();
            }其他{
                STO precord();


这是我更新code:

  //设置文件名用户输入
                。字符串文件名= getInput.getText()的toString()+3GP。
                //显示文件名
                的System.out.println(文件是:+文件名);                //开始记录
                记录=新MediaRecorder();
                recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                recorder.setOutputFile(/ SD卡/音频/+文件名);
                recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
                player.setDataSource(文件名);


解决方案

android.widget.EditText@random数字表示你的 getInput 的EditText ,因此,要获得它的文本,你需要调用它的getText()方法,如下图所示,

 字符串文件名= getInput.getText()的toString()。

I have an app that records and stores the audio on the sdcard. It records and saves it in the right place, but saves it as android.widget.EditText@random number. I was using an EditText to get the filename.

Does anyone know how I can let the user enter some text and save the file as that. I thought I was onto something with the code below, but no...

try {
                    //Set user input as filename
                    String filename = getInput.toString();
                    // set the storage directory to SDcard
                    File storageDir = new File(Environment.getExternalStorageDirectory(), "audio");
                    storageDir.mkdir();
                    Log.d(APP_TAG, "Storage directory set to " + storageDir);

                    outfile = File.createTempFile(filename, ".3gp", storageDir);
                    //show filename
                    System.out.println("File is: "+outfile.getAbsolutePath());

                    // initiate recorder
                    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                    recorder.setOutputFile(outfile.getAbsolutePath());

                } catch (IOException e) {
                    Log.w(APP_TAG, "File not accessible ", e);
                } catch (IllegalArgumentException e) {
                    Log.w(APP_TAG, "Illegal argument ", e);
                } catch (IllegalStateException e) {
                    Log.w(APP_TAG, "Illegal state, call reset/restore", e);
                }
                startRecord();
            } else {
                stopRecord();


here is my updated code:

    //set filename to user input
                String filename = getInput.getText().toString()+".3gp";
                // show filename
                System.out.println("File is: " + filename);

                // initiate recorder
                recorder = new MediaRecorder();
                recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                recorder.setOutputFile("/sdcard/audio/"+filename);
                recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);                    
                player.setDataSource(filename);

解决方案

android.widget.EditText@random number indicates that your getInput is a EditText, So to get its text you need to call its getText() Method, like below,

String filename = getInput.getText().toString(); 

这篇关于Android商店使用输入文本记录的音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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