所以我创建了一个基本的音板,但我现在正在寻找将声卡更新到2.0版本
我想要一个音板,当有人点击一个按钮时,音板会在该特定类别中播放随机声音。
这是我的基本音板代码........
非常感谢您的帮助。
package com.example.benandhollysoundboard;
import android.R.layout;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class myMenu extends Activity {
MediaPlayer ben, holly, gaston, plum, queenthistle, kingthistle, robot, wiseoldelf, lucy;
ImageButton Ben, Holly, Gaston, Plum, Queenthistle, Kingthistle, Robot, Wiseoldelf, Lucy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.Layout.activity_main);
Ben = MediaPlayer.create(this, R.raw.ben);
Ben = (ImageButton) findViewById(R.id.Ben);
Ben.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ben.start();
}
});
holly = MediaPlayer.create(this, R.raw.holly);
Holly = (ImageButton) findViewById(R.id.Holly);
Holly.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holly.start();
}
});
gaston = MediaPlayer.create(this, R.raw.gaston);
Gaston = (ImageButton) findViewById(R.id.Gaston);
Gaston.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gaston.start();
}
});
plum = MediaPlayer.create(this, R.raw.plum);
Plum = (ImageButton) findViewById(R.id.Plum);
Plum.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
plum.start();
}
});
robot = MediaPlayer.create(this, R.raw.robot);
Robot = (ImageButton) findViewById(R.id.Robot);
Robot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
robot.start();
}
});
wiseoldelf = MediaPlayer.create(this, R.raw.wiseoldelf);
Wiseoldelf = (ImageButton) findViewById(R.id.Wiseoldelf);
Wiseoldelf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wiseoldelf.start();
}
});
lucy = MediaPlayer.create(this, R.raw.lucy);
Lucy = (ImageButton) findViewById(R.id.Lucy);
Lucy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lucy.start();
}
});
kingthistle = MediaPlayer.create(this, R.raw.kingthistle);
Kingthistle = (ImageButton) findViewById(R.id.Kingthistle);
Kingthistle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
kingthistle.start();
}
});
queenthistle = MediaPlayer.create(this, R.raw.queenthistle);
Queenthistle = (ImageButton) findViewById(R.id.Queenthistle);
Queenthistle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
queenthistle.start();
}
});
}
}
答案 0 :(得分:0)
嗨我没有进入android开发,但我认为你可以保存数组中每个类别的文件名,然后如果按下按钮生成一个随机数并将其放入数组
例如(生成1到10之间的随机int)
int rand = (int) (Math.random()*10+1);
然后
类似
@Override
public void onClick(View v) {
int rand = (int) (Math.random()*10+1);
Array[rand].start();
}
});
希望我能帮忙;)