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);