0
Hello, good morning. I have an audio in the raw folder, a few seconds long. I want to use this audio when the application opens. When the app starts, it will already start with the audio playing. Can anyone help me do that? Thanks!
0
Hello, good morning. I have an audio in the raw folder, a few seconds long. I want to use this audio when the application opens. When the app starts, it will already start with the audio playing. Can anyone help me do that? Thanks!
1
You need only the class Mediaplayer and use the method start()
to initialize. See:
MediaPlayer mPlayer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPlayer = MediaPlayer.create(this, R.raw.mysoundfile);
mPlayer.start();
}
To stop the audio, just use the method stop()
. Below is an example to stop audio when the application is destroyed. See:
public void onDestroy() {
mPlayer.stop();
super.onDestroy();
}
Browser other questions tagged java android
You are not signed in. Login or sign up in order to post.
Thank you very much!
– user75016
@Adlemelvis for nothing! =)
– viana
How do I learn about these classes and methods? Or will I just learn every time I ask someone? for example: if I need to display a pdf, how will I learn to do this? has something somewhere to study, or I’ll have to ask someone?
– user75016
@Adlemelvis in the documentation has a lot of things. But if you wanted something specific, you can ask here.
– viana
Thank you very much again!
– user75016
I did not find this option. "Validate"
– user75016
Ready. Thank you very much for your patience.
– user75016