我有幾個按鈕。按下時,每個人都會發出不同的聲音。 使用應用程序2或3分鐘後,按鈕停止播放任何聲音。 我會簡化代碼:按鈕停止工作
<Button
android:id="@+id/but"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:background="@drawable/button" />
public class MainActivity extends ActionBarActivity implements View.OnClickListener
{
Button b;
MediaPlayer mp;
MainActivity t=this;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.but);
b.setOnClickListener(this);
}
public void onClick(View v)
{
int q=v.getId();
if(q==R.id.but)
{
mp=MediaPlayer.create(t,R.raw.song);
mp.start();
}
}
什麼是你得到的錯誤。發佈日誌 – Psypher 2015-02-23 17:58:36
歌曲是否在2-3分鐘後完成播放,並且無法再次啓動,或者該按鈕是否無故停止處理點擊? – miselking 2015-02-23 18:01:03
音頻最長10秒。它無故停止處理點擊。 – 2015-02-23 18:06:56