2016-08-04 77 views
2

我試過在這個網站提供的所有解決方案&我仍然得到這個錯誤。不知道爲什麼會發生!請幫幫我。MediaPlayer:錯誤(-19,0)

在這裏我的代碼。

MediaPlayer mediaPlayer; 
    mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.square); 

       mediaPlayer.setOnErrorListener(MainActivity.this); 
       mediaPlayer.start(); 

    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
         @Override 
         public void onCompletion(MediaPlayer mp) { 
          mWinMusic[blocks].release(); 
         } 
        }); 



    public boolean onError(MediaPlayer mp, int what, int extra) { 

    mp = MediaPlayer.create(getApplicationContext(), R.raw.square); 

      mp.start(); 
      return true; 



} 
+0

可以請你分享什麼異常 – Shubh

+0

它是IllegalStateException異常? – Shubh

+0

E/MediaPlayer:錯誤(-19,0) E/MediaPlayer:應該已經設置字幕控制器 –

回答

0

這樣創建的球員,並添加mediaPlayer.prepare();準備就緒時再開始onPrepared()

public class MainActivity extends Activity { 

    MediaPlayer mediaPlayer; 

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

     try { 
      mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.square); 
      mediaPlayer.prepare(); 
      mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
       @Override 
       public void onPrepared(MediaPlayer mp) { 
        mediaPlayer.start(); 
       } 
      }); 
      mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { 
       @Override 
       public boolean onError(MediaPlayer mp, int what, int extra) { 
        Toast.makeText(MainActivity.this, "Some problem ", Toast.LENGTH_LONG).show(); 
        return false; 
       } 
      }); 


      mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
       @Override 
       public void onCompletion(MediaPlayer mp) { 
        Toast.makeText(MainActivity.this, "track completed", Toast.LENGTH_SHORT).show(); 
        //mWinMusic[blocks].release(); 
       } 
      }); 
     } catch (Exception e) { 
      Toast.makeText(MainActivity.this, "Some problem " + e.getMessage(), Toast.LENGTH_LONG).show(); 
     } 
    } 
} 
+0

我試過你的代碼,但拋出空例外所有時間。 –

+0

@MahaMrityunjayaSaraswati你可以在這裏發佈你的日誌嗎?我想看看它的快照嗎? –

+0

E/MediaPlayer的:應該已經設置 E/MediaPlayer的副標題控制器:prepareAsync稱爲狀態8 E/MediaPlayer的:如果有副標題控制器已經設置 –