lawrence
lawrence

Reputation: 39

Android Mediaplayer

i want to play an audio on my android app using the Mediaplayer class. my problem is on the R.java part. to better understand my problem, i'll have to show a part of my code

audioControl = MediaPlayer.create(context, R.raw.forward_100hz);
        audioControl.start();

so, the problem is on the forward_100hz, which is my wav file which is stated that it cannot be resolved or it is not a field. how can i resolve this problem?

Upvotes: 0

Views: 350

Answers (5)

Felipe Peña
Felipe Peña

Reputation: 15

First sure that folder/raw exists and create the Mediaplayer before of on create

MediaPlayer player;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    player=MediaPlayer.create(MainActivity.this,R.raw.forward_100hz);
    player.start();
}

}

Upvotes: -1

As the second parameter of the create method put the following path:

Uri path = Uri.parse("android.resource://<package-name>/"+ R.raw.forward_100hz);

Upvotes: 0

PravinCG
PravinCG

Reputation: 7708

  1. Make sure the file forward_100hz is in res/raw folder
  2. Check your imports and remove import android.R;
  3. If on Eclipse press Ctrl + Shift + O to auto suggest import and you should import

    import your.package.name.R;

  4. If 3 does not work check your manifest file and then res directory for error which might be causing the problem by not generating R.java

Upvotes: 0

strongmayer
strongmayer

Reputation: 488

I think the problem is with your imports. Probably you've already imported the android.R class, but not the R class of your project.

Upvotes: 3

Rajdeep Dua
Rajdeep Dua

Reputation: 11230

Make sure the file is stored in the folder res/raw Try deleting the R file generated by eclipse if the file is in place

Upvotes: 1

Related Questions