码迷,mamicode.com
首页 > 移动开发 > 详细

Android获取声音长度

时间:2015-01-26 16:49:00      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

代码

MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
   metaRetriever.setDataSource(filePath);

String out = "";
   // get mp3 info

  // convert duration to minute:seconds
String duration =  
 metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
Log.v("time", duration);
long dur = Long.parseLong(duration);
String seconds = String.valueOf((dur % 60000) / 1000);

Log.v("seconds", seconds);
String minutes = String.valueOf(dur / 60000);
out = minutes + ":" + seconds;
if (seconds.length() == 1) {
    txtTime.setText("0" + minutes + ":0" + seconds);
}else {
    txtTime.setText("0" + minutes + ":" + seconds);
}
Log.v("minutes", minutes);
  // close object
   metaRetriever.release();

参考地址

http://stackoverflow.com/questions/9834697/how-to-get-the-duration-of-an-mp3-file-in-android?rq=1

Android获取声音长度

标签:

原文地址:http://www.cnblogs.com/niusys/p/4250567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!