我正在制作一个应用程序,我希望它在 Activity 打开时发出声音,声音文件在 R.raw.sound_file
中,如果有人可以做一些示例代码来制作我的应用播放的声音会很棒。
最佳答案
android.media.MediaPlayer
类不做这个吗?
引用:http://developer.android.com/reference/android/media/MediaPlayer.html
示例:http://developer.android.com/guide/topics/media/index.html
示例的第 2 步说:
MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1);
mp.start();
在你的例子中,我会在你的 Activity 类中使用 onStart()
:
public class MyActivity extends Activity {
...
protected void onStart() {
super.onStart();
MediaPlayer mp = MediaPlayer.create(this, R.raw.sound_file_1);
mp.start();
}
...
}
关于java - 我如何才能播放 .wav 声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2458833/