• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Playing an audio file

nilootus

Lurker
Hi Everyone
I want to play an audio file in my application. So i created a folder named "raw" in the res directory of my project and i put the audio file in it. Then i created an activity and in its onCreate method i wrote this:

mp = MediaPlayer.create(PlayAuidioActivity.this, R.raw.EyRabbe);
mp.start();

(mp is my MediaPlayer)

But it has an error. it says that : "raw cannot be resolved or is not a field."

Can someone please tell me what is wrong with this and what should I do to solve it?

Thanks in advance
 
Put the audio file in assets and use:
Java:
String filename = "audio.wav";
AssetFileDescriptor file = null;
MediaPlayer mp = null;
try
{
  file = getAssets().openFd(filename);
  mp = new MediaPlayer();
  mp.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
  mp.prepare();
}
catch (IOException e)
{
  throw new RuntimeException("Couldn't load '" + filename + "'");
}
finally
{
  if (file != null) {
    try {
      file.close();
    } catch (IOException e) {}
  }
}
 
The reason I used R.raw is because I read it in developer.Android site.
Right now I've got another problem :|
from the tab Project I clicked on Clean button and Cleaned my project. The problem was solved. I cleaned the project again and this time a bigger problem occured.
There is no R.java file in my project and my project is full of errors :(

What has happened? :(
 
Back
Top Bottom