How do I play an mp3 in the res/raw folder of my android app?

When starting the activity i.e on onCreate put the following code.

  public void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);         
        setContentView(R.layout.main);

        MediaPlayer mPlayer = MediaPlayer.create(FakeCallScreen.this, R.raw.mysoundfile);
        mPlayer.start();

    }

When stopping the activity i.e on onDestroy put the following code.

   public void onDestroy() {

    mPlayer.stop();
    super.onDestroy();

}

Hope it helps 🙂

Leave a Comment