ローカルクラスでサウンドを再生する代わりに、別のクラスを呼び出してサウンドを再生するコードをダウンロードしました。唯一の問題は、古いコードで音量を調整するために電話の音量キーを使用できないことです。私の地元のクラスで私はそれをすることができました。
以前の方法では、ローカルクラスには次のコードがありました。
AudioManager mgr = (AudioManager) GameScreen_bugfix.this.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
soundPool.play(soundPoolMap.get(sound), volume, volume, 1, 0,1f);
新しいコードは次のようになります。
public static void playSound(int index,float speed)
{
float streamVolume;
try {
streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, speed);
} catch (Exception e) {
e.printStackTrace();
//Log.v("THE ERROR", mSoundPoolMap+" "+index);
}
}
だから私はそれを次のように変更しようとしました:
AudioManager mgr = (AudioManager) SoundManager.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr
.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
しかし、このgetSystemServiceは赤で強調表示され、マウスオーバーすると次のように表示されます。
メソッドgetSystemService(String)は、SoundManagerタイプに対して未定義です。
何をすべきか?ありがとう!