[英]MediaPlayer seekTo random duration
I have a MediaPlayer
and i stream an MP3 file from a link i want the music to be randomize based on the MP3's duration. 我有一个
MediaPlayer
,我从一个链接流式传输MP3文件,我希望音乐根据MP3的持续时间随机化。
I have tried using the
Random
class andgetDuration()
fromMediaPlayer
andseekTo()
but failed maybe because of buffering issue.我尝试使用
MediaPlayer
和seekTo()
的Random
类和getDuration()
,但可能由于缓冲问题而失败。This below code just
reset()
the file because i have failed getting it to a random duration.下面的代码只是
reset()
文件,因为我无法将其设置为随机持续时间。 Please help me out请帮帮我
try {
mediaPlayer.setDataSource(MainActivity.this, uri);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IOException e) {
dialog.dismiss();
}
Try this for random position: 试试这个随机位置:
randomPosition = ThreadLocalRandom.current().nextInt(0, mediaPlayer.getDuartion() + 1);
Then seek: 然后寻找:
mediaPlayer.seekTo(randomPosition);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.