so easy
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(audioUrl);
mediaPlayer.prepare();
int duration = mediaPlayer.getDuration();
if (0 != duration) {
//更新 seekbar 长度
seekbar.setMax(duration);
int s = duration / 1000;
//设置文件时长,单位 "分:秒" 格式
String total = s / 60 + ":" + s % 60;
//记得释放资源
mediaPlayer.release();
}
} catch (IOException e) {
e.printStackTrace();
}
网友评论