How do I play music on Android?

Asked 2 years ago, Updated 2 years ago, 25 views

I'm making an app, and I want to keep printing background music or something, but I don't know what to do.

android

2022-09-21 18:23

1 Answers

First, create a folder called raw in the res folder and save the music file you want to print there. And

public class MusicActivity extends Activity{
    @override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mp = MediaPlayer.create (this, R.raw.music file name);
        mp.setLooping(true);
        mp.start();
    }
}

You can do it like this.


2022-09-21 18:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.