错误播放声音上的一个按钮点击 [英] Error in playing the sound on a button click
本文介绍了错误播放声音上的一个按钮点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经加了两个ImageButton的到我的活动,并在点击每一个应该发挥不同的声音。
但是,当我点击任何按钮的声音没有得到发挥和日志显示错误。
I have added two imageButton to my activity and on Clicking each one should play different sounds. But when I click on any Button the sound doesn't get play and the log shows error.
logcat的错误
09-30 15:19:07.436: D/dalvikvm(477): GC_EXTERNAL_ALLOC freed 629 objects / 50520 bytes in 180ms
09-30 15:19:10.226: E/MediaPlayer(477): start called in state 1
09-30 15:19:15.276: E/MediaPlayer(477): start called in state 1
下面是一块code的,我写的,
Here is the piece of code which I wrote,
import android.media.MediaPlayer;
public class MainActivity extends Activity {
MediaPlayer mp;
ImageButton iV1,iV2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iV1 = (ImageButton)findViewById(R.id.iV1);
iV2 = (ImageButton)findViewById(R.id.iV2);
mp = MediaPlayer.create(this, R.raw.bud);
mp = MediaPlayer.create(this, R.raw.classic);
iV1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
mp = new MediaPlayer();
mp.prepare();
mp.start();
}});
iV2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
mp = new MediaPlayer();
mp.prepare();
mp.start();
}});
}
}
请帮我在这。任何帮助将AP preciated。我是新来这个环境中的Android。
Please help me on this. Any help will be appreciated. I am New to this environment of Android.
先谢谢了。
推荐答案
这是一个状态机的问题,因为日志清清楚楚地写着:
This is a state machine issue, as the log clearly says :
09-30 15:19:10.226: E/MediaPlayer(477): start called in state 1
参见:
的http://developer.android.com/reference/android/media/MediaPlayer.html#StateDiagram
如,我不明白,你在哪里调用
e.g., I dont see, where you are calling
MediaPlayer.setDataSource();
MediaPlayer.Prepare()
这篇关于错误播放声音上的一个按钮点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文