2011-12-20 2 views
0

게임을 시작하면서 배경 음악을 재생하고 싶은 메모리 게임을 개발 중입니다.전체 게임 중 배경 음악 재생

사운드 풀 클래스를 사용하고 성공적으로 실행했지만 재생하는 데 문제가 있습니다. 나는 .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); 

      } 
     }); 
+0

"2 메모리 게임 개발"이란 무엇을 의미합니까? 접두어 2를 왜 사용 했습니까? – Lion

+0

질문 편집 – mH16

+0

@Lion 지금보십시오 (질문을 읽을 수 있도록 최선을 다했습니다.) –

답변

5

Soundpool가 배경 음악에 사용되는 것은 아닙니다 한 OnCreate 기능 .IN 주어진 activitycalss이 클래스를 사용했다. 파일 크기로드 및 재생 시간과 같은 많은 제한 사항이 있습니다. 주로 음향 효과에 사용됩니다. 배경 음악으로 MediaPlayer 클래스를 사용합니다.

+0

감사합니다. mediapalyer에서이 파일을 재생하려고 시도합니다. – Thamilvanan

+0

@ Thamilvanan :이 답변이 도움이된다면, 동의로 표시하십시오. –

+0

헤이 배경 음악을 위해 meadiaplayer를 사용했습니다. 감사합니다. – Thamilvanan