2014-04-13 184 views
0

我使用此代碼播放在線MP3音頻,當我點擊按鈕,但它不起作用。android MediaPlayer播放在線(外部)音頻

public void play(View v) throws IllegalStateException, IOException{ 
    MediaPlayer em2 =MediaPlayer.create(this, Uri.parse("https://ia801005.us.archive.org/22/items/sslamweb.blogspot.com_201308/Maher%20Zain%20-%20Hold%20My%20Hand%20-%20Official%20Lyrics%20Video.mp3")); 
    em2.setAudioStreamType(AudioManager.STREAM_MUSIC); 
    em2.prepare(); 
    em2.start();   
} 

回答

0

您正在使用create,爲您調用prepare已經創建MediaPlayer。不要再撥打prepare

public void play(View v) throws IllegalStateException, IOException{ 
    MediaPlayer em2 = MediaPlayer.create(this, Uri.parse("https://ia801005.us.archive.org/22/items/sslamweb.blogspot.com_201308/Maher%20Zain%20-%20Hold%20My%20Hand%20-%20Official%20Lyrics%20Video.mp3")); 
    em2.setAudioStreamType(AudioManager.STREAM_MUSIC); 
    em2.start();   
} 

將來,它將有助於查看logcat輸出的錯誤。

相關問題