2011-10-02 4 views
0

나는 사운드 풀을 사용하여 버튼 클릭으로 임의의 사운드 FX를 재생하려고합니다. 이것은 에뮬레이터에서는 작동하지만 내 장치에서는 작동하지 않습니다. 모든 단서?Android : 무작위 사운드 FX 버튼 클릭

public class enc extends Activity { 
private static final String TAG = "MyActivity"; 

private SoundPool soundPool; 
private HashMap<Integer, Integer> soundsMap; 
int SOUND1=1; 
int SOUND2=2; 
int SOUND3=3; 
int SOUND4=4; 
int SOUND5=5; 
int SOUND6=6; 
int SOUND7=7; 
int SOUND8=8; 
int fSpeed = 1; 

Random random = new Random(); 
int hit = random.nextInt(6)+1; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //SoundPool 
    soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); 
    soundsMap = new HashMap<Integer, Integer>(); 
    soundsMap.put(SOUND1, soundPool.load(this, R.raw.hit1, 1)); 
    soundsMap.put(SOUND2, soundPool.load(this, R.raw.hit2, 1)); 
    soundsMap.put(SOUND3, soundPool.load(this, R.raw.hit3, 1)); 
    soundsMap.put(SOUND4, soundPool.load(this, R.raw.hit4, 1)); 
    soundsMap.put(SOUND5, soundPool.load(this, R.raw.hit5, 1)); 
    soundsMap.put(SOUND6, soundPool.load(this, R.raw.hit6, 1)); 
    soundsMap.put(SOUND7, soundPool.load(this, R.raw.spell, 1)); 
    soundsMap.put(SOUND8, soundPool.load(this, R.raw.kill, 1)); 


    setContentView(R.layout.enc); 

} 


public void setButtonClickListener() { 
    Button wepb = (Button)findViewById(R.id.uwep); 
    wepb.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Log.i(TAG, "----------------------------SFX: " + hit); 
      playSound(hit, fSpeed); 
      hit = random.nextInt(6)+1; 
        } 
    }); 
} 
} 
+0

장치에서 작동하지 않는다고하면 어떻게됩니까? – slayton

+0

휴대 전화에 설치하면 소리가 재생되지 않습니다. 임의의 정수를 사용하지 않고 풀에서 소리를 호출하면 정상적으로 작동합니다. 미디어 플레이어를 사용할 때도 같은 문제가 발생했습니다. – cerealspiller

+0

난수가 제대로 생성 되었습니까? 로그 메시지를 게시 할 수 있습니까? – slayton

답변

0

이 문제점을 발견했습니다. MP3 파일을 사용하고 있었고 Android 2.0 이상은 OGG 파일에서만 작동합니다. 그들 모두를 MP3에서 OGG로 변환하면 문제가 해결되었습니다. 모두 잘됐다!