我曾尝试在类中使用MediaPlayer并在MainActivity上调用该类,但应用程序仍在崩溃。我试着搜索,但无法找到办法。任何想法?
public class TestMedia extends MainActivity {
public void Test01(){
MediaPlayer mediaPlayer0 = MediaPlayer.create(getApplicationContext(), R.raw.one);
mediaPlayer0.start();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TestMedia test02 = new TestMedia();
test02.Test01();}
答案 0 :(得分:0)
提供的代码段很奇怪,为什么要实例化" TestMedia" in" onCreate()" " TestMedia"?
活动类不应该像这样实例化。
尝试替换
TestMedia test02 = new TestMedia();
test02.Test01();
带
MediaPlayer mediaPlayer0 = MediaPlayer.create(getApplicationContext(), R.raw.one);
mediaPlayer0.start();