gpt4 book ai didi

android - MediaPlayer导致FC错误

转载 作者:行者123 更新时间:2023-12-03 02:26:09 24 4
gpt4 key购买 nike

好的,我收到此FC错误。

我已经检查了三遍代码,并尝试了两次重写。这是我能够学习的最有效的代码。但是我仍然得到FC。
我会为我的程序播放大约50个声音文件,对此我将不胜感激。每次 Activity 15至20之间。

implements OnClickListener {
MediaPlayer mp1;
MediaPlayer mp2;
MediaPlayer mp3;
MediaPlayer mp4;
MediaPlayer mp5;
MediaPlayer mp6;
MediaPlayer mp7;



public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.verbs);

mp1 = MediaPlayer.create(this, R.raw.play);
mp2 = MediaPlayer.create(this, R.raw.eat);
mp3 = MediaPlayer.create(this, R.raw.can);
mp4 = MediaPlayer.create(this, R.raw.go);
mp5 = MediaPlayer.create(this, R.raw.help);
mp6 = MediaPlayer.create(this, R.raw.practice);
mp7 = MediaPlayer.create(this, R.raw.use);





final Button button1 = (Button) findViewById(R.id.play_button);
button1.setOnClickListener(this);

final Button button2 = (Button) findViewById(R.id.eat_button);
button2.setOnClickListener(this);

final Button button3 = (Button) findViewById(R.id.can_button);
button3.setOnClickListener(this);

final Button button4 = (Button) findViewById(R.id.go_button);
button4.setOnClickListener(this);

final Button button5 = (Button) findViewById(R.id.Thelp_button);
button5.setOnClickListener(this);

final Button button6 = (Button) findViewById(R.id.pract_button);
button6.setOnClickListener(this);

final Button button7 = (Button) findViewById(R.id.use_button);
button7.setOnClickListener(this);

final Button button8 = (Button) findViewById(R.id.Back_Button);
button8.setOnClickListener(this);



}

public void onClick(View v) {
switch(v.getId()) {
case R.id.play_button:
mp1.start();
Toast.makeText(VerbsActivity.this, "PLAY",
Toast.LENGTH_LONG).show();
break;
case R.id.eat_button:
mp2.start();
Toast.makeText(VerbsActivity.this, "EAT",
Toast.LENGTH_LONG).show();
break;
case R.id.can_button:
mp3.start();
Toast.makeText(VerbsActivity.this, "CAN",
Toast.LENGTH_LONG).show();
break;
case R.id.go_button:
mp4.start();
Toast.makeText(VerbsActivity.this,"GO",
Toast.LENGTH_LONG).show();
break;
case R.id.Thelp_button:
mp5.start();
Toast.makeText(VerbsActivity.this,"HELP",
Toast.LENGTH_LONG).show();
break;
case R.id.pract_button:
mp6.start();
Toast.makeText(VerbsActivity.this, "PRACTICE",
Toast.LENGTH_LONG).show();
break;
case R.id.use_button:
mp7.start();
Toast.makeText(VerbsActivity.this, "USE",
Toast.LENGTH_LONG).show();
break;

case R.id.Back_Button:
finish();
break;

}
}

@Override
protected void onDestroy() {
mp1.release();
mp2.release();
mp3.release();
mp4.release();
mp5.release();
mp6.release();
mp7.release();

super.onDestroy();
}

}

最佳答案

您创建了太多MediaPlayer对象,这些对象很容易导致异常。您还可以通过onDestroy()方法释放它们,在很多情况下不会调用该方法。

更改您的代码以改为使用SoundPool。

关于android - MediaPlayer导致FC错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4864586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com