package com.uygulamalar.androidce;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;
public class EglenceliSeslerActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
ToggleButton togg1,togg2,togg3,togg4,togg5,togg6,togg7,togg8,togg9;
MediaPlayer sincap,seytanikahkaha,bateri,kalpatisi,trololo,kedicanini,haha,alkis,dedeler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
togg1 = (ToggleButton) findViewById(R.id.togg1);
togg2 = (ToggleButton) findViewById(R.id.togg2);
togg3 = (ToggleButton) findViewById(R.id.togg3);
togg4 = (ToggleButton) findViewById(R.id.togg4);
togg5 = (ToggleButton) findViewById(R.id.togg5);
togg6 = (ToggleButton) findViewById(R.id.togg6);
togg7 = (ToggleButton) findViewById(R.id.togg7);
togg8 = (ToggleButton) findViewById(R.id.togg8);
togg9 = (ToggleButton) findViewById(R.id.togg9);
sincap = MediaPlayer.create(this, R.raw.dramatiksincap);
seytanikahkaha = MediaPlayer.create(this, R.raw.seytanikahkaha);
bateri = MediaPlayer.create(this, R.raw.bateri);
kalpatisi = MediaPlayer.create(this, R.raw.kalpatisi);
trololo = MediaPlayer.create(this, R.raw.trololo);
kedicanini = MediaPlayer.create(this, R.raw.kedicanini);
haha = MediaPlayer.create(this, R.raw.haha);
alkis = MediaPlayer.create(this, R.raw.alkis);
dedeler = MediaPlayer.create(this, R.raw.dedeler);
togg1.setOnClickListener(this);
togg2.setOnClickListener(this);
togg3.setOnClickListener(this);
togg4.setOnClickListener(this);
togg5.setOnClickListener(this);
togg6.setOnClickListener(this);
togg7.setOnClickListener(this);
togg8.setOnClickListener(this);
togg9.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.togg1:
if(togg1.isChecked()) {
sincap.start();
sincap.setLooping(true);
}
else
sincap.pause();
case R.id.togg2:
if(togg2.isChecked()) {
seytanikahkaha.start();
seytanikahkaha.setLooping(true);
}
else
seytanikahkaha.pause();
case R.id.togg3:
if(togg3.isChecked()) {
bateri.start();
bateri.setLooping(true);
}
else
bateri.pause();
case R.id.togg4:
if(togg4.isChecked()) {
kalpatisi.start();
kalpatisi.setLooping(true);
}
else
kalpatisi.pause();
case R.id.togg5:
if(togg5.isChecked()) {
trololo.start();
trololo.setLooping(true);
}
else
trololo.pause();
case R.id.togg6:
if(togg6.isChecked()) {
kedicanini.start();
kedicanini.setLooping(true);
}
else
kedicanini.pause();
}
}
}
为什么其他切换按钮在我点击它们时除了第一个以外没有播放音频?第一个切换按钮播放音频sincap很好,但其他人不能播放音频。你能告诉我为什么吗? THX。
答案 0 :(得分:0)
在每个case
之后,您应该有一个break
语句,这样您就不会陷入下一个案例。即:
...
switch(v.getId()) {
case R.id.togg1:
if(togg1.isChecked()) {
sincap.start();
sincap.setLooping(true);
}
else
sincap.pause();
break;
case R.id.togg2:
if(togg2.isChecked()) {
seytanikahkaha.start();
seytanikahkaha.setLooping(true);
}
else
seytanikahkaha.pause();
break;
...