0

サウンドプールを使用して、ボタンのクリックでランダムなサウンド 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;
                    }
    });
}
}
4

1 に答える 1

0

問題が見つかりました。私は MP3 ファイルを使用していましたが、どうやら Android 2.0+ は OGG ファイルでしか動作しません。それらをすべてMP3からOGGに変換すると修正されました。すべては順調です!

于 2011-10-04T03:51:24.153 に答える