public class ExecutaSomExemplo {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Conecta o button do xml
Button button = (Button)findViewById(R.id.myButton);
//Método de ação do clique
button.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
//Cria o objeto MediaPlayer que irá receber o arquivo de som
MediaPlayer mPlayer = MediaPlayer.create(MainActivity.this, R.raw.nomedoarquivo);
//Toca a música
mPlayer.start();
}
}
);
}
}
In your specific case where you are using the Eclipse
the briefcase raw
does not come created as default, you have to create it: right click on the res folder, select Novo...
afterward Pasta
and type the folder name as in the image:
So, you can create new files there, either by dragging-and-dropping the file inside it, or right-click again on the raw folder and select Novo...
and then Arquivo
.
but I cannot use this method because there is no R.raw.filename address, error when I try to use "raw cannot be resolved or is not a field"
– Jeiferson
Make sure the file is of the type
.mp3
example: filename.mp3, also make sure the file is in the directoryres/raw
of your project. If everything is right, give aClean/Build
and try to rotate again.– iTSangar
But there is no Raw folder, that is my doubt, there is no such folder in my project, I am using the latest version of ADT Plugin
– Jeiferson
Which IDE are you using @Jeiferson? Eclipse, Netbeans, Android Studio?
– iTSangar
IDE Eclipse @iTSangar
– Jeiferson
I added a brief solution to your case in the answer I created @Jeiferson, in case you need anything else just say =)
– iTSangar
Vlw man, that was it...
– Jeiferson