2014-04-13 143 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输出的错误。

相关问题