0

I have got several mp3 files added as raw resource to my project. I would like to play them with AudioPlayer. I had FileNotfoundException and I backtraced it to find that the files can be found but they are not readable: 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
        }

I cannot call file.setReadable() because I use API level 7.

My manifest:

   <?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 Answers1

1

Try

  MediaPlayer mPlayer = MediaPlayer.create(PlayWorld.this, R.raw.your_mp3);
Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61
  • I already created the mediaplayer formerly. Actualy I want it to play a different sound than It was playing before. I would presume that you can call mPlayer.create() only once. – user1105818 Oct 02 '13 at 16:42
  • @user1105818 http://developer.android.com/reference/android/media/MediaPlayer.html – Raghunandan Oct 02 '13 at 16:50