声音按钮在一段时间后停止工作

时间:2017-12-17 18:21:05

标签: java android android-layout android-studio view

我的Android应用程序有问题。它的条形音箱应用程序。 运行后,一切都很完美。一段时间后点击按钮,我有错误:

E/MediaPlayer: start called in state 0, mPlayer(0x7d176f4300)
E/MediaPlayer: error (-38, 0)

我在三星S7上运行,我会要求理解因为我是初学者。我看到了类似的主题,但我找不到能帮助我的答案。这是我的代码:

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final MediaPlayer AaaCoJeszcze = MediaPlayer.create(this, R.raw.aaa_co_jeszcze);
        Button But1 = this.findViewById(R.id.Button1);
        But1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AaaCoJeszcze.start();
            }
        });

        final MediaPlayer CoNieMoznaMP = MediaPlayer.create(this, R.raw.co_nie_mozna);
        Button But2 = this.findViewById(R.id.Button2);
        But2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CoNieMoznaMP.start();
            }
        });

        final MediaPlayer CoToJaWinnyMP = MediaPlayer.create(this, R.raw.co_to_ja_winny);
        Button But3 = this.findViewById(R.id.Button3);
        But3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CoToJaWinnyMP.start();
            }
        });

        final MediaPlayer debilMP = MediaPlayer.create(this, R.raw.debil);
        Button But4 = this.findViewById(R.id.Button4);
        But4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                debilMP.start();
            }
        });

        final MediaPlayer iTenMP = MediaPlayer.create(this, R.raw.i_ten_o_co_chodzi);
        Button But5 = this.findViewById(R.id.Button5);
        But5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iTenMP.start();
            }
        });

        final MediaPlayer JedziemyMP = MediaPlayer.create(this, R.raw.jedziemy_z_kurwami);
        Button But6 = this.findViewById(R.id.Button6);
        But6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                JedziemyMP.start();
            }
        });

        final MediaPlayer JegoMP = MediaPlayer.create(this, R.raw.jego_robota_moze_poczekac);
        Button But7 = this.findViewById(R.id.Button7);
        But7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                JegoMP.start();
            }
        });

        final MediaPlayer ZanimMP = MediaPlayer.create(this, R.raw.zanim_podeszlem);
        Button But8 = this.findViewById(R.id.Button8);
        But8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ZanimMP.start();
            }
        });

        final MediaPlayer MozePanOdejscMP = MediaPlayer.create(this, R.raw.moze_pan_odejsc);
        Button But9 = this.findViewById(R.id.Button9);
        But9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MozePanOdejscMP.start();
            }
        });

        final MediaPlayer MozeZrobilPomylkeMP = MediaPlayer.create(this, R.raw.moze_zrobil_pomylke);
        Button But10 = this.findViewById(R.id.Button10);
        But10.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MozeZrobilPomylkeMP.start();
            }
        });

        final MediaPlayer MowiszTakTakMP = MediaPlayer.create(this, R.raw.mowisz_tak_tak);
        Button But11 = this.findViewById(R.id.Button11);
        But11.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MowiszTakTakMP.start();
            }
        });

        final MediaPlayer PaniMnieMP = MediaPlayer.create(this, R.raw.pani_mnie_rozprasza);
        Button But12 = this.findViewById(R.id.Button12);
        But12.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PaniMnieMP.start();
            }
        });

        final MediaPlayer PrawdopodobnieMP = MediaPlayer.create(this, R.raw.prawdopodobnie_polak);
        Button But13 = this.findViewById(R.id.Button13);
        But13.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PrawdopodobnieMP.start();
            }
        });

        final MediaPlayer ProszeNiePrzeszkadzacMP = MediaPlayer.create(this, R.raw.prosze_nie_przeszkadzac_dobrze);
        Button But14 = this.findViewById(R.id.Button14);
        But14.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ProszeNiePrzeszkadzacMP.start();
            }
        });

        final MediaPlayer PrzepraszamPaniaMP = MediaPlayer.create(this, R.raw.przepraszam_pania_spoczko);
        Button But15 = this.findViewById(R.id.Button15);
        But15.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PrzepraszamPaniaMP.start();
            }
        });

        final MediaPlayer RozpraszaMP = MediaPlayer.create(this, R.raw.rozprasza_mnie);
        Button But16 = this.findViewById(R.id.Button16);
        But16.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RozpraszaMP.start();
            }
        });

        final MediaPlayer RozumiszMP = MediaPlayer.create(this, R.raw.rozumisz);
        Button But17 = this.findViewById(R.id.Button17);
        But17.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RozumiszMP.start();
            }
        });

        final MediaPlayer spoczkoMP = MediaPlayer.create(this, R.raw.spoczko);
        Button But18 = this.findViewById(R.id.Button18);
        But18.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                spoczkoMP.start();
            }
        });

        final MediaPlayer SzefiemozeszMP = MediaPlayer.create(this, R.raw.szefie_mozesz_odejsc);
        Button But19 = this.findViewById(R.id.Button19);
        But19.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SzefiemozeszMP.start();
            }
        });

        final MediaPlayer AleodejdzMP = MediaPlayer.create(this, R.raw.szefie_odejdz_ale_odejdz);
        Button But20 = this.findViewById(R.id.Button20);
        But20.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AleodejdzMP.start();
            }
        });

        final MediaPlayer MozeMP = MediaPlayer.create(this, R.raw.moze_moze_moze);
        Button But21 = this.findViewById(R.id.Button21);
        But21.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MozeMP.start();
            }
        });

        final MediaPlayer RekoczynyMP = MediaPlayer.create(this, R.raw.zadnych_rekoczynow);
        Button But22 = this.findViewById(R.id.Button22);
        But22.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RekoczynyMP.start();
            }
        });

        final MediaPlayer PowinnoDojscMP = MediaPlayer.create(this, R.raw.juz_powinno_dojsc);
        Button But23 = this.findViewById(R.id.Button23);
        But23.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PowinnoDojscMP.start();
            }
        });

    }}

0 个答案:

没有答案