Error when trying to use MediaPlayer

0

I tried to create a Button that when pressed performs a sound, but I know how to import that sound and I do not know how to find the Raw folder when I try to use this line:

mpSongButtons = MediaPlayer.create(MainActivity.this, R.raw.);

Of the error, that is, this Raw does not exist, could anyone help me?

    
asked by anonymous 17.02.2015 / 01:54

1 answer

2
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 Eclipse the raw folder is not created by default, you have to create it: right-click on the res folder, select Novo... after Pasta and enter the folder name, as in the image:

Then you can create new files there, either by dragging and dropping the file into it, or right-click the raw folder and select% with% and then% with%.

    
17.02.2015 / 02:55