Answers for "how to add music file to android studio"

1

How to add music to andoid project

MediaPlayer mediaPlayer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.yoursong);

    mediaPlayer.start();

}

@Override
protected void onPause() {
    super.onPause();
    mediaPlayer.stop();
    mediaPlayer.release();

}
Posted by: Guest on May-27-2021

Code answers related to "how to add music file to android studio"

Browse Popular Code Answers by Language