Sei sulla pagina 1di 4

sign up

Stack Overflow

log in

Questions Tags Users Badges Unanswered Ask

Read this post in our app!

-1

EditText text use as filename


android

android-edittext

soundpool

I have application that will search for song on external storage and play it by clicking a button. I use String path =
getFullFilePath(getApplicationContext(), "FILENAME"); and it works fine if i type something like song.mp3...I tried to use EditText.getText().toString();
except "FILENAME" and it doesnt work. This is my code in OnCreate:
EditText et = (EditText) findViewById(R.id.et1);
String string = et.getText().toString();
sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
String path = getFullFilePath(getApplicationContext(), string);
mSoundId = sp.load(path, 1);

And LogCat says `11-07 14:26:39.909: W/SoundPool(12627): sample 1 not READY


BUT if I input et.setText("SongName"); it works fine.. I want to type something in edittext and then use it as filename! Thanks `

share

improve this question


Tom Jackson
130 1 10

Asked
Nov 7 '12 at 13:34

slezadav
4,191 4 22 51

Edited
Nov 7 '12 at 13:36

In OnCreate is there any event happening like Button Click or something. Then on button click you get text from edittext. Raghunandan Nov 7 '12 at 13:37

Only this is in my button click public void button1(View view) { if (mStreamId != 0) { sp.stop(mStreamId); } mStreamId = sp.play(mSoundId, 1, 1, 1, 0, 1f); } Tom Jackson Nov 7
'12 at 13:40
add a comment

2 Answers

Order By

Votes

Do this in OnCreate:
mEditText = (EditText) findViewById(R.id.et1);
mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
mSoundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
public void onLoadComplete (SoundPool soundPool, int sampleId, int status) {
mStreamId = soundPool.play(sampleId, 1, 1, 1, 0, 1f);
}
}

Then in your onClick do:


public void yourOnClickMethod(View view) {
if (mStreamId != 0) {
mSoundPool.stop(mStreamId);
}

share

String path = getFullFilePath(getApplicationContext(), EditText.getText().toString());


mSoundId = mSoundPool.load(path, 1);

improve this answer


PKeno
965 2 9 31

Answered
Nov 7 '12 at 13:52

Edited
Nov 7 '12 at 15:12

11-07 15:07:01.659: W/SoundPool(14064): sample 1 not READY Tom Jackson Nov 7 '12 at 14:07

check out this question and SoundPool.OnLoadCompleteListener. It takes a while for the sample to be ready. PKeno Nov 7 '12 at 15:06
add a comment

share

OnCreate will only be called one time for each lifetime of the Activity. So OnCreate is used to initialize UI. So it does not get the
change on EditText. Have a button. On Click get the data from edittext. That should solve your problem.

improve this answer


Raghunandan
90.7k 11 119 172

Answered
Nov 7 '12 at 13:41

I did like this if (mStreamId != 0) { sp.stop(mStreamId); } String path = getFullFilePath(getApplicationContext(), mEditText.getText().toString()); mSoundId = sp.load(path, 1);
mStreamId = sp.play(mSoundId, 1, 1, 1, 0, 1f); } And i am getting same error. Tom Jackson Nov 7 '12 at 14:07
stackoverflow.com/questions/5202510/soundpool-sample-not-ready. stackoverflow.com/questions/7786314/. Have a look a these links. Raghunandan Nov 7 '12 at 14:20
if i type in edittext filename that doesnt exist on my external storage then i get something like this 11-07 15:24:35.219: E/SoundPool(14487): error loading /mnt/sdcard/dub.mp3
But if i put dub2.mp3 that exists i get 11-07 15:24:35.219: E/SoundPool(14487): error loading /mnt/sdcard/dub.mp3 and everytime i click the button again it gives sample 2 not
ready..next time sample 3 not ready... Tom Jackson Nov 7 '12 at 14:27
add a comment

Your Answer

log in
or

Name

Email

By posting your answer, you agree to the privacy policy and terms of service.

meta chat tour help blog privacy policy legal contact us full site
Download the Stack Exchange Android app
2016 Stack Exchange, Inc

Post Your Answer

Potrebbero piacerti anche