3个回答
展开全部
java中直接使用AudioInputStream类来操作音乐文件,获取时长,实例如下:
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
public class AudioLength {
public static void main(String[] args) throws LineUnavailableException,
UnsupportedAudioFileException, IOException {
File file = new File("d:/test.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
clip.open(ais);
System.out.println( clip.getMicrosecondLength() / 1000000D + " s" );//获取音频文件时长
}
}
展开全部
调用DLL文件,只要找到一个可以比较好解析播放时长的DLL,然后JNI调用,CPP或者Delphi都好,只要能实现就oK了,DLL放在BIN目录;
PS:问题解决;
Java代码
public class CtrlFtpFile {
//读取Dll
static {
System.loadLibrary("GetPlayTime");
}
public native String getMediaTime(String arg);
public static void main(String[] args) {
CtrlFtpFile hw = new CtrlFtpFile();
// System.out.println(hw.getMediaTime("D:\\TDDOWNLOAD\\小强.mp3"));
System.out.println(hw.getMediaTime("file:///G:/tomcat/apache-tomcat-6.0.18/webapps/mbs/ftp/0/real/B1224487037153.mpeg"));
//file:///G:\tomcat\apache-tomcat-6.0.18\webapps\mbs\ftp\0/real/B1224487037153.mpeg
}
}
调用方法:String.valueOf(ftpFile.getPlaytime());因为得到是一个秒数字符串;
那个附件到参考资料那个网站下载就行
:"http://jatula.javaeye.com/blog/259328"
PS:问题解决;
Java代码
public class CtrlFtpFile {
//读取Dll
static {
System.loadLibrary("GetPlayTime");
}
public native String getMediaTime(String arg);
public static void main(String[] args) {
CtrlFtpFile hw = new CtrlFtpFile();
// System.out.println(hw.getMediaTime("D:\\TDDOWNLOAD\\小强.mp3"));
System.out.println(hw.getMediaTime("file:///G:/tomcat/apache-tomcat-6.0.18/webapps/mbs/ftp/0/real/B1224487037153.mpeg"));
//file:///G:\tomcat\apache-tomcat-6.0.18\webapps\mbs\ftp\0/real/B1224487037153.mpeg
}
}
调用方法:String.valueOf(ftpFile.getPlaytime());因为得到是一个秒数字符串;
那个附件到参考资料那个网站下载就行
:"http://jatula.javaeye.com/blog/259328"
参考资料: http://jatula.javaeye.com/blog/259328
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
调用DLL文件,只要找到一个可以比较好解析播放时长的DLL,然后JNI调用,CPP或者Delphi都好,只要能实现就oK了,DLL放在BIN目录;
PS:问题解决;
Java代码
public class CtrlFtpFile {
//读取Dll
static {
System.loadLibrary("GetPlayTime");
}
public native String getMediaTime(String arg);
public static void main(String[] args) {
CtrlFtpFile hw = new CtrlFtpFile();
// System.out.println(hw.getMediaTime("D:\\TDDOWNLOAD\\小强.mp3"));
System.out.println(hw.getMediaTime("file:///G:/tomcat/apache-tomcat-6.0.18/webapps/mbs/ftp/0/real/B1224487037153.mpeg"));
//file:///G:\tomcat\apache-tomcat-6.0.18\webapps\mbs\ftp\0/real/B1224487037153.mpeg
}
}
调用方法:String.valueOf(ftpFile.getPlaytime());因为得到是一个秒数字符串;
那个附件到参考资料那个网站下载就行
:"http://jatula.javaeye.com/blog/259328"
PS:问题解决;
Java代码
public class CtrlFtpFile {
//读取Dll
static {
System.loadLibrary("GetPlayTime");
}
public native String getMediaTime(String arg);
public static void main(String[] args) {
CtrlFtpFile hw = new CtrlFtpFile();
// System.out.println(hw.getMediaTime("D:\\TDDOWNLOAD\\小强.mp3"));
System.out.println(hw.getMediaTime("file:///G:/tomcat/apache-tomcat-6.0.18/webapps/mbs/ftp/0/real/B1224487037153.mpeg"));
//file:///G:\tomcat\apache-tomcat-6.0.18\webapps\mbs\ftp\0/real/B1224487037153.mpeg
}
}
调用方法:String.valueOf(ftpFile.getPlaytime());因为得到是一个秒数字符串;
那个附件到参考资料那个网站下载就行
:"http://jatula.javaeye.com/blog/259328"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询