简体   繁体   中英

How to save audio in sd-card based on spinner value

I am creating application of recording audio and save it inside SD-card. So when user tap on record audio button a pop-up is coming which ask user to enter audio name. So with this pop-up i have added one spinner which basically loads data from database.

So what i want to do is whenever user select any value from spinner then with that particular name a new folder should automatically create and save that audio inside that folder.

Ex. say i have 5 value in spinner A, B, C, D, and E, so when user select A and press OK button then i want to create folder name Called A inside SD-card and that audio should store inside A Folder. same as with others if user select B then i want to create folder B inside SD-card and it should store that audio inside B folder.

spinnerListData.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View v,
                int position, long id) {
            Toast.makeText(getApplicationContext(),
                    "Spinner Item selected", Toast.LENGTH_LONG).show();

                String filepath = Environment.getExternalStorageDirectory().getPath() + AUDIO_RECORDER_FOLDER;
                String path = filepath + String.valueOf(Code.audioName) + ".mp4";
                recorder.setOutputFile(path);

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

So this is basic code which saves audio inside AudioRecorder folder of SD-card. But i don't know how to achieve what i wanted to do. If anyone have any idea or sample code then please help me.

You can specify the selected item from spinner and put it with the file path. Suppose you have array passed to spinner String [] spinnerItem; , you can get the clicked item and create folder as below:

String filepath = Environment.getExternalStorageDirectory().getPath() + spinnerItem[position];
            String path = filepath + String.valueOf(Code.audioName) + ".mp4";
            recorder.setOutputFile(path);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM