作成したアニメーションに音声を追加したいと考えています。アニメーションが始まるたびに、おそらくサウンドも開始する必要がありますが、サウンドを開始することができません。
アニメーションはすべて問題ありません。コードは次のとおりです。
public class TestActivity extends Activity {
AnimationDrawable anim;
MediaPlayer mp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
playAnimation(R.id.frameLayout1,R.drawable.anim2,R.raw.bang);
}
public void playAnimation(int FrameLayoutAddress, int animationXMLAdress, int soundAddress)
{
mp = MediaPlayer.create(this.getApplicationContext(), soundAddress);
mp.start(); // error here
FrameLayout imgView = (FrameLayout)findViewById(FrameLayoutAddress);
imgView.setBackgroundResource(animationXMLAdress);
anim = (AnimationDrawable) imgView.getBackground();
imgView.post(new Runnable()
{
@Override
public void run()
{
anim.start();
}
});
}
}
誰でも私の間違いを指摘できますか? お時間をいただきありがとうございます。