MediaPlayer启动调用状态0(错误-38,0),android?

时间:2014-01-03 13:22:43

标签: android android-mediaplayer

我正在制作Android音板应用,而且我已经投放了很多MediaPlayer值。

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

    bengalka = MediaPlayer.create(this, R.raw.bengalka);
    psiho = MediaPlayer.create(this, R.raw.cista_psihologija);
    dane = MediaPlayer.create(this, R.raw.da_ne);
    dejo = MediaPlayer.create(this, R.raw.dejo_narkomane);
    pod = MediaPlayer.create(this, R.raw.dizi_se);
    fejs = MediaPlayer.create(this, R.raw.fejslifting);
    foto = MediaPlayer.create(this, R.raw.fotomale);
    hungry = MediaPlayer.create(this, R.raw.gladan_sam);
    jasna = MediaPlayer.create(this, R.raw.jasna_pero);
    jeben = MediaPlayer.create(this, R.raw.jeben_vam_mater);
    kae = MediaPlayer.create(this, R.raw.kae_ivanisevic);
    fora = MediaPlayer.create(this, R.raw.kae_to_fora);
    gledas = MediaPlayer.create(this, R.raw.kaj_gledas);
    gledate = MediaPlayer.create(this, R.raw.kaj_vi_gledate);
    kinezi = MediaPlayer.create(this, R.raw.kineza_crnaca);
    kozo = MediaPlayer.create(this, R.raw.kozo_nepodojena);
    marino = MediaPlayer.create(this, R.raw.marino);
    mater = MediaPlayer.create(this, R.raw.mater_zbrgljavu);
    muha = MediaPlayer.create(this, R.raw.muha);
    papir = MediaPlayer.create(this, R.raw.nema_papira);
    nered = MediaPlayer.create(this, R.raw.nered);
    majku = MediaPlayer.create(this, R.raw.ne_spominji_majku);
    uroko = MediaPlayer.create(this, R.raw.nisam_se_uroko);
    odfurati = MediaPlayer.create(this, R.raw.odfurati_doktoru);
    pljacka = MediaPlayer.create(this, R.raw.pljacka);
    puske = MediaPlayer.create(this, R.raw.pusi_ke);
    sava = MediaPlayer.create(this, R.raw.sava_sava);
    magazin = MediaPlayer.create(this, R.raw.tebe_i_magazin);
    vani = MediaPlayer.create(this, R.raw.tog_vani_nema);
    dom = MediaPlayer.create(this, R.raw.za_dom_spremni);
    zrigati = MediaPlayer.create(this, R.raw.zrigati);

我已经实现了OnClickListener方法..

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.button1:
        bengalka.start();
        break;
    case R.id.button2:
        psiho.start();
        break;
    case R.id.button3:
        dane.start();
        break;
    case R.id.button4:
        dejo.start();
        break;
    case R.id.button5:
        pod.start();
        break;
    case R.id.button6:
        fejs.start();
        break;
    case R.id.button7:
        foto.start();
        break;
    case R.id.button8:
        hungry.start();
        break;
    case R.id.button9:
        jasna.start();
        break;
    case R.id.button10:
        jeben.start();
        break;
    case R.id.button11:
        kae.start();
        break;
    case R.id.button12:
        fora.start();
        break;
    case R.id.button13:
        gledas.start();
        break;
    case R.id.button14:
        gledate.start();
        break;
    case R.id.button15:
        kinezi.start();
        break;
    case R.id.button16:
        kozo.start();
        break;
    case R.id.button17:
        marino.start();
        break;
    case R.id.button18:
        mater.start();
        break;
    case R.id.button19:
        muha.start();
        break;
    case R.id.button20:
        papir.start();
        break;
    case R.id.button21:
        nered.start();
        break;
    case R.id.button22:
        majku.start();
        break;
    case R.id.button23:
        uroko.start();
        break;
    case R.id.button24:
        odfurati.start();
        break;
    case R.id.button25:
        pljacka.start();
        break;
    case R.id.button26:
        puske.start();
        break;
    case R.id.button27:
        sava.start();
        break;
    case R.id.button28:
        magazin.start();
        break;
    case R.id.button29:
        vani.start();
        break;
    case R.id.button30:
        dom.start();
        break;
    case R.id.button31:
        zrigati.start();
        break;
    }

现在,当我点击它们时,一些按钮不起作用,我查看了LogCat,它说:

MediaPlayer |开始在状态0中调用

MediaPlayer |错误(-38,0)

2 个答案:

答案 0 :(得分:5)

您正在尝试启动媒体播放器,但尚未准备好。尝试使用OnPreparedListener(),并在播放器准备就绪时启动播放器,它应该看起来像这样:

yourMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer player) {
  player.start();
  }
});

答案 1 :(得分:0)

我猜有些文件包含android不支持的编码。尝试在常规播放器中播放这些文件。

请参阅this链接。