找到你要的答案

Q:Add sound on Android Studio Application

Q:在Android Studio应用程序上添加声音

How do I add a sound effect to a game when the mission is over? I am currently using Android Studio also.

当任务结束时,我如何给游戏添加音效?我目前使用Android工作室也。

answer1: 回答1:

I think you should use the MediaPlayer class.

Here the doc : http://developer.android.com/reference/android/media/MediaPlayer.html

我认为你应该使用MediaPlayer类。

这里的医生:http://developer.android.com/reference/android/media/mediaplayer.html

answer2: 回答2:

You need to first get hold of the sound that you need to play when the mission is over. example. Using a .wav file. Next place the .wav file in the raw folder in the res folder. You can find the sound you need free on sites which provide the same. Next in your code where you need to play the sound.

  private SoundPool sounds;
  private int sExplosion;
  //declare variables
  sounds = new SoundPool(10, AudioManager.STREAM_MUSIC,0);
  sExplosion = sounds.load(context, R.raw.explode, 1);
  sounds.play(sExplosion, 1.0f, 1.0f, 0, 0, 1.5f);

here explode.wav is the sound that i need to play

当任务结束时,你需要先掌握你需要播放的声音。例子.wav文件使用。其次,在res文件夹中的原始文件夹的WAV文件。你可以找到的声音,你需要免费提供相同的网站。下一步在您的代码中,您需要播放的声音。

  private SoundPool sounds;
  private int sExplosion;
  //declare variables
  sounds = new SoundPool(10, AudioManager.STREAM_MUSIC,0);
  sExplosion = sounds.load(context, R.raw.explode, 1);
  sounds.play(sExplosion, 1.0f, 1.0f, 0, 0, 1.5f);

这里explode.wav就是我需要播放声音

android  audio  effects