解决方案 »
- 关于CTS编译的问题
- 天气预报中的短信发送
- android & wcf 问题
- 求教Framelayout布局问题
- drawpicture怎么画图,我怎么就化不出来了,谁给我写段能划出图的代码,copy的也行 我就想看看怎么能划出图来
- android网络应用开发问题
- 为什么linux编译的程序能运行,用ndk编译后的就不能运行了呢
- 求问一个支付宝问题,服务器有公钥和私钥,我客户端能用服务器的公钥和私钥吗?
- 求YUV420P的格式转换为RGB565的demo
- 相对布局怎么居中后靠上一点,设置margintop 为负数不管用
- 求大神 关于unity3d C#与 xml的问题
- eclipse emulator control unable to send command to emulator 求解
setDataSource 这个函数只是告诉mediaplayer要播放的文件的url,你的mediaplayer这时候还没加载这个文件
获取duration:
try {
mp.setDataSource(file.getAbsolutePath());
mp.prepare();
} catch (Exception e) {}
player.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
int size = mp.getDuration();
}
});
/*
* 函数介绍:获取文件细节
* 输入参数:file,文件
* 输出参数:无
* 返回值 :字符串数组
*/
private String[] getPVRfiledetails(File file) {
Log.i(TAG, "getPVRfiledetails is called");
String[] strArray = new String[4];
String strName = file.getName();
strArray[0] = "DATE : ";
strArray[1] = "TIME : ";
strArray[2] = "SIZE : ";
strArray[3] = "DURATION : ";
//P2007-01-20-23-23-32-1537.pvr
if (strName.length() >= 26) {
strArray[0] += strName.substring(1, 11);
strArray[1] += strName.substring(12, 20);
}
else {
strArray[0] += "....-..-..";
strArray[1] += "..-..-..";
}
long lSize = file.length();
if (lSize < 1024) {
strArray[2] += lSize + "bytes";
}
else if (lSize < 1024*1024) {
strArray[2] += lSize/1024 + "Kbytes";
}
else if (lSize < 1024*1024*1024) {
strArray[2] += lSize/(1024*1024) + "Mbytes";
}
else {
strArray[2] += lSize/(1024*1024*1024) + "Gbytes";
}
String strPath = file.getAbsolutePath();
MediaPlayer mp = new MediaPlayer();
try {
if (mp != null) {
mp.setDataSource(strPath);
mp.prepare();
int second = mp.getDuration() / 1000;
if (second < 60) {
strArray[3] += second + "sec(s)";
}
else if (second < (60*60)) {
strArray[3] += second/60 + "min(s)";
}
else {
strArray[3] += second/(60*60) + "hr(s)";
}
mp.release();
mp = null;
}
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return strArray;
}