使用首选项edittext除文件名

时间:2012-11-06 15:21:37

标签: android preferences

我有应用程序搜索外部存储空间以查找我想要的文件。示例为名为sound1.mp3 String path = getFullFilePath(getApplicationContext(), "sound1.mp3);的歌曲。我使用加载的声音用于soundpool。我想从Preference Edittext获取文本并使用它除了“sound1.mp3”..我试过这个:

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给出了这个:

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

1 个答案:

答案 0 :(得分:0)

根据您的LogCat,您zipStr中存储的路径是/mnt/sdcard

SoundPool.load需要音频文件的路径(请参阅文档:SoundPool.load())。

确保您的zipStr等同于/mnt/sdcard/sound1.mp3