一段时间后,Android MediaPlayer无法正常工作

时间:2019-07-10 10:45:06

标签: android android-mediaplayer

在Android中,MediaPlayer一会儿无法使用。代码如下:

播放音乐:

sayib1 = (ImageButton)findViewById(R.id.sayib1);
sayib2 = (ImageButton)findViewById(R.id.sayib2);
sayib3 = (ImageButton)findViewById(R.id.sayib3);
sayib4 = (ImageButton)findViewById(R.id.sayib4);
sayib5 = (ImageButton)findViewById(R.id.sayib5);
sayib6 = (ImageButton)findViewById(R.id.sayib6);
sayib7 = (ImageButton)findViewById(R.id.sayib7);
sayib8 = (ImageButton)findViewById(R.id.sayib8);
sayib9 = (ImageButton)findViewById(R.id.sayib9);

mpsayi = new MediaPlayer();

final String sourcestr = "android.resource://" + this.getPackageName();

sayib1.setOnClickListener(new View.OnClickListener () {
    public void onClick (View sayiv1){

        mpsayi.reset();

        mpsayi.seekTo(0);

        sayilayoutt1.setVisibility(View.INVISIBLE);
        sayilayoutt2.setVisibility(View.INVISIBLE);
        sayibutonlar.setVisibility(View.INVISIBLE);

        sayiimagev.setImageResource(R.drawable.sayi1);
        sayiimagev.setVisibility(View.VISIBLE);

        new Handler().postDelayed( new Runnable() {

            public void run(){

                sayilayoutt1.setVisibility(View.VISIBLE);
                sayilayoutt2.setVisibility(View.VISIBLE);
                sayibutonlar.setVisibility(View.VISIBLE);

                sayiimagev.setVisibility(View.INVISIBLE);

            }

        }, 1500);

        mpsayi = MediaPlayer.create(getApplicationContext(), R.raw.bir);
        mpsayi.start();
    }
});

sayib2.setOnClickListener(new View.OnClickListener () {
    public void onClick (View sayiv2){

        mpsayi.reset();
        mpsayi.seekTo(0);

        sayilayoutt1.setVisibility(View.INVISIBLE);
        sayilayoutt2.setVisibility(View.INVISIBLE);
        sayibutonlar.setVisibility(View.INVISIBLE);

        sayiimagev.setImageResource(R.drawable.sayi2);
        sayiimagev.setVisibility(View.VISIBLE);

        new Handler().postDelayed( new Runnable() {

            public void run(){

                sayilayoutt1.setVisibility(View.VISIBLE);
                sayilayoutt2.setVisibility(View.VISIBLE);
                sayibutonlar.setVisibility(View.VISIBLE);

                sayiimagev.setVisibility(View.INVISIBLE);

            }

        }, 1500);

        mpsayi = MediaPlayer.create(getApplicationContext(), R.raw.iki);
        mpsayi.start();

    }
});

当我单击ImageButton时,将播放音乐。

Video Demonstration

如何解决此问题?希望你能理解。

0 个答案:

没有答案