게임을 시작하면서 배경 음악을 재생하고 싶은 메모리 게임을 개발 중입니다.전체 게임 중 배경 음악 재생
사운드 풀 클래스를 사용하고 성공적으로 실행했지만 재생하는 데 문제가 있습니다. 나는 .mp3
오디오 파일을 2 분 추가했지만 더 15 초만 더 재생합니다.
아무도 내가 갖고있는 문제를 말할 수 있습니까? 이건 내 soundclass 파일입니다
public class Soundclass {
private SoundPool soundpool;
private HashMap<Integer, Integer> soundpoolmap;
private AudioManager audiomanager;
private Context context;
public void initSounds(Context thecontext) {
context = thecontext;
soundpool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundpoolmap = new HashMap<Integer, Integer>();
audiomanager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
}
public Soundclass() {
}
public void addSound(int Index, int soundID) {
soundpoolmap.put(Index, soundpool.load(context, soundID, 1));
}
public void playSound(int Index) {
float streamVolume = audiomanager
.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume
/audiomanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
soundpool.play(soundpoolmap.get(Index), streamVolume, streamVolume, 1,
0, 1f);
}
public void playLoopedSound(int Index) {
float streamVolume = audiomanager
.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume
/audiomanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
soundpool.play(soundpoolmap.get(Index), streamVolume, streamVolume, 1,
-1, 1f);
}
}
와 나는
Button btn = (Button) findViewById(R.id.sound);
soundclass = new Soundclass();
soundclass.initSounds(getBaseContext());
soundclass.addSound(1, R.raw.jinglebells);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
soundclass.playSound(1);
}
});
"2 메모리 게임 개발"이란 무엇을 의미합니까? 접두어 2를 왜 사용 했습니까? – Lion
질문 편집 – mH16
@Lion 지금보십시오 (질문을 읽을 수 있도록 최선을 다했습니다.) –