0

我有一个按钮,每次点击我都想播放不同的声音。我需要一些帮助才能让第二个声音正常工作。到目前为止,这是我的代码:

package com.andrew.finnandjake;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Main extends Activity {
private SoundManager mSoundManager;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mSoundManager = new SoundManager();
    mSoundManager.initSounds(getBaseContext());
    mSoundManager.addSound(1, R.raw.finn_whatthejugisthat);
    mSoundManager.addSound(2, R.raw.finn_wordtoyourmother);


    Button SoundButton = (Button)findViewById(R.id.Button1);
    SoundButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            mSoundManager.playSound(1);
            mSoundManager.playSound(2);


        }
    });
}
}
4

1 回答 1

0

我将创建一个迭代器,每次单击按钮时都会递增,然后使用 if 语句根据迭代器的值确定要播放的声音。

于 2011-03-02T04:38:23.213 回答