我有几个 mp3 文件作为原始资源添加到我的项目中。我想用 AudioPlayer 播放它们。我有 FileNotfoundException 并且我回溯它以发现可以找到文件但它们不可读:mp1.stop(); mp1.reset();
playedSound = R.raw.sip02;
String str = getResources().getString(playedSound);
File file = new File(str);
//((File)file).setReadable(true);
boolean readable = file.canRead(); //returns TRUE
file.setReadOnly();
readable = file.canRead(); //returns TRUE
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace(); //enters this branch
}
我无法调用 file.setReadable() 因为我使用 API 级别 7。
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.movingcircle"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.movingcircle.MovingCircle"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>