2014-04-27 2 views
1

아래 코드에있는 동일한 음악의 여러 인스턴스를 어떻게 재생합니까? 한 번에 2 개의 다른 사운드를 연주하는 경우에도 해당 코드는 어디에 두어야합니까? 다음과 같이사운드 풀에서 여러 인스턴스 연주

public class SoundManager { 

private SoundPool msoundPool; 
private HashMap<Integer, Integer> mSoundPoolMap; 
private AudioManager maudioManager; 
private Context mContext; 

public SoundManager() 
{ 

} 

public void initSounds(Context theContext) 
{ 
    mContext=theContext; 
    msoundPool=new SoundPool(4, AudioManager.STREAM_MUSIC,0); 
    mSoundPoolMap=new HashMap<Integer, Integer>(); 
    maudioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); 

} 

public void addSounds(int Index,int soundId) 
{ 
    mSoundPoolMap.put(1, msoundPool.load(mContext, soundId,1)); 
} 

public void playSound(int index) 
{ 
    int streamVolume=maudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
    msoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f); 
} 

public void playLoopedSound(int index) 
{ 
    int streamVolume=maudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
    msoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, -1,1f); 
} 
} 

내 주요 방법은 : 나는에서 onCreate 방법이 불렀다

 m=new SoundManager(); 
    m.initSounds(getBaseContext()); 
    m.addSounds(1, R.raw.sound); 
    Button button=(Button)findViewById(R.id.button11); 
    button.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      m.playSound(1); 

     } 
    }); 
} 

답변

0

예제 코드 :

Music music = MusicFactory.createMusicFromAsset(pMusicManager, pContext, pAssetPath); 
Music music2 = MusicFactory.createMusicFromAsset(pMusicManager, pContext, pAssetPath); 

music.play; 
music2.play;