注:私はちょっとしたことですので、これらのエラーの意味は分かりません。SoundPool型のメソッドload(Context、int、int)は適用されません。メソッドgetSystemService(String)は定義されていません
これは私のクラスのコードです:
package ryan.test;
import java.util.HashMap;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
public class MySingleton {
private MySingleton instance;
private static SoundPool mSoundPool;
private HashMap<Integer, Integer> soundPoolMap;
public static final int A1 = 1;
private MySingleton() {
mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);// Just an example
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(A1, mSoundPool.load(this, R.raw.a, 1));
// soundPoolMap.put(A5, mSoundPool.load(MyApp.this, R.raw.a, 1));
}
public synchronized MySingleton getInstance() {
if(instance == null) {
instance = new MySingleton();
}
return instance;
}
public void playSound(int sound) {
AudioManager mgr = (AudioManager)MySingleton.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent/streamVolumeMax;
mSoundPool.play(soundPoolMap.get(sound), volume, volume, 1, 0, 1f);
}
public SoundPool getSoundPool() {
return mSoundPool;
}
}
そして、私は2つのエラーを取得し、最初のエラーはここにあるのです:
soundPoolMap.put(A1, mSoundPool.load(this, R.raw.a, 1));
とエラーがThe method load(Context, int, int) in the type SoundPool is not applicable for the arguments (MySingleton, int, int)
が言うと、2番目のエラーはここにあります:
AudioManager mgr = (AudioManager)MySingleton.getSystemService(Context.AUDIO_SERVICE);
と表示され、エラーはと表示されます。
いいえ、バックグラウンドで音楽をロードしてから、すべてのアクティビティから同じ音楽を呼び出します。 – Ryan