【发布时间】:2016-07-27 12:35:18
【问题描述】:
我正在尝试将文件从Environment.getExternalStorageDirectory() 加载到SoundPool。该文件存在,但我仍然得到 p>
E/SoundPool: error loading /storage/emulated/0/dialpad/sounds/mamacita_us/one.mp3
当我尝试加载它时。在真实设备上,它从完全相同的路径完美运行。
这是我用来加载文件的代码:
if( isExternalStorageReadable() ){
String externalStorageAbsolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();
String soundFilesPath = (new File(externalStorageAbsolutePath, "dialpad/sounds/mamacita_us")).getPath();
Log.d("DEBUG", (new File(soundFilesPath, "one.mp3")).getAbsolutePath() );
Log.d("DEBUG", (new File(soundFilesPath, "one.mp3")).exists() ? "EXISTS" : "DOES NOT EXSIST");
sounds.put("1", soundPool.load((new File(soundFilesPath, "one.mp3")).getAbsolutePath(), 1));
sounds.put("2", soundPool.load( (new File(soundFilesPath, "two.mp3")).getPath(), 1 ));
}
isExternalStorageReadable() 是一个辅助方法:
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
LogCat 输出说
D/DEBUG: /storage/emulated/0/dialpad/sounds/mamacita_us/one.mp3
D/DEBUG: EXISTS
我有一个想法,可能是文件权限问题,但我不知道... ls -l in adb shell 给我
-rw-rw---- root sdcard_rw 18288 2009-07-06 13:42 one.mp3
-rw-rw---- root sdcard_rw 21422 2009-07-06 13:44 two.mp3
已尝试使用chmod 更改权限,但它们从未更改。我已经使用adb push 将文件推送到模拟器。
有人知道如何解决这个问题吗?正如我所说,它在相同路径的真实设备上完美运行,因此 Genymotion 模拟器和/或文件系统似乎存在问题。模拟器运行的是 Android 6.0 (API23)。
哦,是的,我要声明
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
在我的清单中。
【问题讨论】:
标签: android android-emulator adb genymotion android-file