注意:我是个菜鸟,所以真的不知道这些错误是什么意思。
这是我的课程代码:
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;
}
}
我收到两个错误,第一个错误在这里:
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)
第二个错误在这里:
AudioManager mgr = (AudioManager)MySingleton.getSystemService(Context.AUDIO_SERVICE);
错误说The method getSystemService(String) is undefined for the type MySingleton