2014-01-19 90 views
-2

我是Android開發的初學者。我用的MediaPlayer類的Android的播放文件。但它與媒體播放器錯誤的錯誤筍(-19,0)Android中的MediaPlayer無法正常工作

package com.example.sound_play; 

import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class Sound extends Activity { 

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

     Button b = (Button) findViewById(R.id.button1); 
     b.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       MediaPlayer mp = MediaPlayer.create(Sound.this, R.raw.n); 
       mp.start(); 
      } 
     }); 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.sound, menu); 
     return true; 
    } 

} 

和我得到的錯誤是:

01-18 15: 39:36.233:E/MediaPlayer的(601):錯誤(-19,0)

+0

你正在試圖對什麼類型的文件? –

+0

我使用的大小爲360kb,比特率爲101kbps,長度爲0:28的.mp3文件。 –

回答

0

你是不是打後釋放的球員,這 - 添加

mp.setOnCompletionListener(new OnCompletionListener() 
{ 
    public void onCompletion(MediaPlayer mp) 
    { 
     mp.release(); 

    }; 
}); 

希望,這將幫助你。

+0

Bro:D愛你的男人...... !!!它的工作絕對:D感謝很多兄弟:D –

相關問題