Answers for "How to add music to andoid project"

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 to andoid project"

Browse Popular Code Answers by Language