Android原始资源文件不可读

时间:2013-10-02 16:35:34

标签: android file-permissions android-2.2-froyo

我有几个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>

1 个答案:

答案 0 :(得分:1)

尝试

  MediaPlayer mPlayer = MediaPlayer.create(PlayWorld.this, R.raw.your_mp3);