我想播放Mp3 URL,我已经使用了媒体播放器。 它正在工作,但准备和开始需要太多时间,我已经参考了许多网站,但我没有得到任何满意的解决方案。
我一直坚持下去,所以请大家帮忙解决!!
我的代码如下所示
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
}
尝试使用
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((
希望对你有帮助