Reputation: 39
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
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
Reputation: 389
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
Reputation: 7708
import your.package.name.R;
Upvotes: 0
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
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