音関連

[edit]

MediaPlayer(BGMなど)

 se = MediaPlayer.create(getContext(), R.raw.sound1);
 se.start();
[edit]

SoundPool(SEなど)

 (1) 管理クラスの生成
 SoundPool soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
 (2) 音声ファイルの読み込み
 int soundId1 = soundPool.load(context resId1, 1);
 int soundId1 = soundPool.load(context, R.raw.lalala, 1);
 (3) 再生
 int streamId1 = soundPool.play(soundId1, 1.0F, 1.0F, 0, 0, 1.0F); 
 (4) 再生停止             soundPool.stop(streamId1);
 (5) リソースの破棄          soundPool.unload(soundId1);
 (6) 管理クラスの破棄         soundPool.release();

再生する音声の種類を指定する.ゲームで音声を再生する場合は,*AudioManager.STREAM_MUSICを指定する.

[edit]

音量調節を可能にする

onCreate() の中で

 setVolumeControlStream(AudioManager.STREAM_MUSIC);