android:每次点击时播放不同的声音

发布于 2024-10-20 00:31:09 字数 1009 浏览 1 评论 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);


        }
    });
}
}

I have a button and on each click I want a different sound to play. I need some help getting the second sound to work. Here's my code so far:

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);


        }
    });
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静被遗忘 2024-10-27 00:31:09

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

I would create an iterator that increments each time the button is clicked, and then use if statements to determine which sound to play based on the value of the iterator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文