使用首选项编辑文本,文件名除外



我有应用程序在外部存储中搜索我想要的文件。名为 sound1 的歌曲示例.mp3String path = getFullFilePath(getApplicationContext(), "sound1.mp3);。我使用加载的声音作为声池。我想从首选项编辑文本中获取文本并使用它,除了"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

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

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

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

相关内容

最新更新