0

I rewrote my sound class to catch an exception so that it no longer crashes the application when the sound is called. The problem still remains that the sound file will not play. It runs and plays on the emulator.

No errors until I test with my HTC VIVID. I don't think my phone is the issue.

My file structure for the sound file is Resources>raw>soundfiles.ogg

Here is the code I am using for my sound class.

public class Sound extends Activity
{
   MediaPlayer mp;
   Context context;
public Sound (Context res)
    {
           context=res;
    }

        public void playSound(int ID) 
        {
         try {
                mp = MediaPlayer.create(context, ID);
                mp.start();

                mp.setOnCompletionListener(new OnCompletionListener() {

                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        mp.release();
                        mp = null;

                    }
                });
            } catch (Exception exception) {
            }   
        }   
}

Here is the logcat:

E/AndroidRuntime(  981): FATAL EXCEPTION: main
E/AndroidRuntime(  981): android.content.res.Resources$NotFoundException: File r
es/raw/soundfile.ogg from drawable resource ID #0x7f040000
E/AndroidRuntime(  981):        at android.content.res.Resources.openRawResource
Fd(Resources.java:1081)
E/AndroidRuntime(  981):        at android.media.MediaPlayer.create(MediaPlayer.
java:762)


E/AndroidRuntime(  981): Caused by: java.io.FileNotFoundException: This file can
 not be opened as a file descriptor; it is probably compressed

How do I fix this compression issue?

Here is a rough outline of the setup. I dont think this is part of the issue.

final Context res;
    Sound fx;




 public GameView(Context context) //reference to activity 
    {
        super(context);
        res=context;
        fx=new Sound(res);


public boolean onTouchEvent(MotionEvent event)
{

            fx.playSound(R.raw.sound);
Kevin
  • 81
  • 4
  • Where are you keeping your sound files? What folder? – jmishra Jul 07 '12 at 21:42
  • "My file structure for the sound file is Resources>raw>soundfiles.ogg " – Kevin Jul 07 '12 at 21:44
  • Can you post the line where you set the context and the id. Possibly the method where you do so – jmishra Jul 07 '12 at 21:52
  • I mean the place where you use your `Sound` class as an instantiated object and call `playSound` on it – jmishra Jul 07 '12 at 22:02
  • I added a rough outline of the setup to the post. The issue is that the sound file is not transferring and being read properly when installed on the phone. Emulator works perfectly. – Kevin Jul 07 '12 at 22:07

1 Answers1

0

The sound file was converted in such a way that it would allow the emulator to read the file but the phone was not able to access it correctly. Upon replacing all sound files with fresh sound files the program again runs as it is supposed to :)

Here are some things that helped me figure out the problem for anyone with this issue in the future:

http://ponystyle.com/blog/2010/03/26/dealing-with-asset-compression-in-android-apps/ http://code.google.com/p/android-apktool/issues/detail?id=153 Problem while opening Asset File with the help of Content Provider

While some of these did not fix my problem they made it possible to find the solution.

Community
  • 1
  • 1
Kevin
  • 81
  • 4