如何在jsp中计算上传的mp3文件的持续时间
我已经使用inf JSP 上传了一个mp3 文件。有没有办法以秒为单位查找上传的 mp3 文件的持续时间?
下面给出的是代码的一部分:
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
System.out.println("Content Type:"+contentType);
System.out.println("PATAH:"+saveFile);
System.out.println("Start :"+startPos);
System.out.println("endPos :"+endPos);
System.out.println("contentLength"+formDataLength);//Size of the file in Bytes
I have uploaded an mp3 file usinf JSP. Is there any way to find the duration of the uploaded mp3 file in seconds?
Given below is the part of the code:
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
System.out.println("Content Type:"+contentType);
System.out.println("PATAH:"+saveFile);
System.out.println("Start :"+startPos);
System.out.println("endPos :"+endPos);
System.out.println("contentLength"+formDataLength);//Size of the file in Bytes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅通过文件大小不可能知道音频长度,最好的方法是使用库来做到这一点。
使用 MP3 SPI: http://www.javazoom.net/mp3spi/documents.html
示例代码,返回音频文件有多少秒:
It is not possible to know the audio length only by the file size, the best way is to using a library to do it.
Using MP3 SPI: http://www.javazoom.net/mp3spi/documents.html
example code, that return how many seconds the audio file has: