我想播放Mp3网址,我已经使用了媒体播放器。它正在工作,但它花了太多时间准备和开始,我已经提到了许多网站,但我还没有得到任何满意的解决方案。
我坚持这一点,所以请大家帮忙解决它!
我的代码如下所示
try {
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(mArrayList.get(0).MUSIC_URL);
player.prepare();
player.start();
seekbar.setMax(player.getDuration());
seekUpdation();
} catch (Exception e) {
// TODO: handle exception
}
答案 0 :(得分:0)
尝试使用
mMediaPlayer.prepareAsync();
如果您看到该文档,解释将是这样的
* Prepares the player for playback, asynchronously.
*
* After setting the datasource and the display surface, you need to either
* call prepare() or prepareAsync(). For streams, you should call prepareAsync(),
* which returns immediately, rather than blocking until enough data has been
* buffered.
在你的情况下,你是流数据,所以需要使用 prepareAsync()
希望有所帮助