0

I have application that searchs External storage for the file i want..Example for song named sound1.mp3 String path = getFullFilePath(getApplicationContext(), "sound1.mp3); .I use loaded sound for soundpool. I want to get text from Preference Edittext and use it except "sound1.mp3".. I tried this :

super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         SharedPreferences getPrefs = PreferenceManager
                    .getDefaultSharedPreferences(getBaseContext());
            SharedPreferences settings = getSharedPreferences("EditText",0);
            String zipStr = settings.getString("ime", "");   
        sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
        String path = getFullFilePath(getApplicationContext(), zipStr);
        Log.d("ime", "Path: " + path);
        mSoundId = sp.load(path, 1);

LogCat gives this :

11-06 15:57:59.169: D/ime(5688): Path: /mnt/sdcard
11-06 15:57:59.539: E/SoundPool(5688): Unable to load sample: (null)
11-06 15:58:01.149: W/asset(5688): deep redirect failure from 0x0103003e => 0x02060007, defStyleAttr=0x00000000, defStyleRes=0x00000000, style=0x00000000
11-06 15:58:17.509: W/SoundPool(5688):   sample 1 not READY
Tom Jackson
  • 230
  • 3
  • 17

1 Answers1

0

The path you have stored in zipStr is, according to your LogCat, /mnt/sdcard

SoundPool.load requires the path to an audio file (see documentation: SoundPool.load()).

make sure your zipStr is equal to something like /mnt/sdcard/sound1.mp3.

PKeno
  • 2,694
  • 7
  • 20
  • 37
  • That would not work. All i want is to get text from zipStr and use it as filename – Tom Jackson Nov 06 '12 at 16:05
  • I'm not sure i understand. What you do now is use zipStr as a path (or file name). The problem is that the path stored in your `SharedPreferences` is not a path to an audio file. Can you please post the method `getFullFilePath` – PKeno Nov 06 '12 at 16:18
  • It is used as filename private String getFullFilePath(Context context, String filename) { File directory = Environment.getExternalStorageDirectory(); File file = new File(directory, filename); if (!file.canRead()) { // error handling } return file.getAbsolutePath(); – Tom Jackson Nov 06 '12 at 16:19
  • Your `getFullFilePath` will return `/mnt/sdcard` if `filename` is an empty string. Meaning you do not have anything stored in your `settings.getString("ime", "");` and the default value `""` is returned. How do you put your filename into shared preferences? – PKeno Nov 06 '12 at 16:27
  • You need to do the following when setting your filename: `SharedPreferences getPrefs = PreferenceManager .getDefaultSharedPreferences(getBaseContext()); SharedPreferences settings = getSharedPreferences( "EditText",0); SharedPreferences.Editor editor = settings.edit(); editor.putString("ime","sound1.mp3"); editor.commit();` Make sure you remember the last `commit`, it is easy to forget ;) – PKeno Nov 06 '12 at 16:34