我想通过单击按钮打开和关闭声音。打开/关闭声音
public void onClick(View v) {
buttonSound.setBackgroundResource(R.drawable.soundan);
CommonMethod.soundplayer.stop();
//buttonSound.setBackgroundResource(R.drawable.soundaus);
//CommonMethod.soundplayer.setVolume(0,0);
}
这是的commonMethod
public class CommonMethod {
public static MediaPlayer soundplayer;
public static void Soundplayer(Context ctx,int raw_id)
{
soundplayer = MediaPlayer.create(ctx,raw_id);
soundplayer.setLooping(true);
soundplayer.setVolume(100, 100);
}
}
它通过单击停止声音,但它不打开它再次
我得到这个代码太多,但其同样的问题
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
if (counter % 2 == 0) {
buttonSound.setBackgroundResource(R.drawable.soundan);
CommonMethod.soundplayer.setVolume(100,100);
}
else
{
buttonSound.setBackgroundResource(R.drawable.soundaus);
CommonMethod.soundplayer.setVolume(0,0);
}
}
什么问题?另外,这不是Eclipse的问题。 – zgc7009
如果我关掉它不能再次打开的声音 –
soundaus或soundan检查 – phpdroid