私はゲームを開始している間にバックグラウンドミュージックをしたいと思うメモリゲームを開発しています。ゲーム全体でバックグラウンドミュージックを再生する
サウンドプールクラスを使用して正常に実行しましたが、再生に問題があります。私は.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(私は質問を読みやすくするために私の最善を尽くして) –