- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 java 6 ,我正在尝试加载 wav 文件,以获取其持续时间如下:
public static double getAudioFileDuration(File file) {
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(file);
// At present, ALAW and ULAW encodings must be converted
// to PCM_SIGNED before it can be played
AudioFormat format = stream.getFormat();
if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(), format.getSampleSizeInBits(),
format.getChannels(), format.getFrameSize(),
format.getFrameRate(), true); // big endian
stream = AudioSystem.getAudioInputStream(format, stream);
}
DataLine.Info info = new DataLine.Info(Clip.class,
stream.getFormat(),
((int) stream.getFrameLength() * format.getFrameSize()));
Clip clip = (Clip) AudioSystem.getLine(info);
// clip.open(stream);
double durationInSecs = clip.getBufferSize()
/ (clip.getFormat().getFrameSize() * clip.getFormat()
.getFrameRate());
double minTemp = Math.round(Math.round(durationInSecs) / 60.0);
double durationInMin = minTemp
+ (((Math.round(durationInSecs) / 60.0) - minTemp) * 60)
/ 100;
return durationInMin;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
但对于某些 WAV 文件,我无法获取持续时间,并且出现以下异常:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1170)
at com.xeno.advertisingsuite.web.utils.GeneralUtils.getAudioFileDuration(GeneralUtils.java:163)
at com.xeno.advertisingsuite.web.beans.AdPageBean.saveAudioFileRef(AdPageBean.java:183)
at com.xeno.advertisingsuite.web.beans.AdPageBean.fileListener(AdPageBean.java:149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at org.icefaces.ace.component.fileentry.FileEntry.broadcast(FileEntry.java:306)
at org.icefaces.ace.component.fileentry.FileEntryPhaseListener$1.visit(FileEntryPhaseListener.java:97)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIForm.visitTree(UIForm.java:344)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at org.icefaces.ace.component.fileentry.FileEntryPhaseListener.beforePhase(FileEntryPhaseListener.java:102)
at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:99)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:60)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:57)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:110)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
关于如何解决这个异常的任何想法,或者是否有另一种获取文件持续时间的方法?
最佳答案
..any ideas how to fix this exception, ..
自 WAV is a container format ,它可能在内部包含任意数量的编码。
..
wav
files can be encoded with a variety of codecs to reduce the file size (for example the GSM or MP3 codecs).
参见 Java Sound info. page有关详细信息,请参阅如何添加对额外编码的支持(使用 SPI)以及 MP3 SPI 上的线索。
..or if there's another way to get file duration ?
不是真的。对于压缩格式,比特率是可变的,并且无法确定轨道需要多长时间才能将其转换为 PCM 或类似格式,在这些格式中,比特率是恒定的并且轨道时间完全确定。
关于javax.sound.sampled.UnsupportedAudioFileException : could not get audio input stream from input file when loading wav file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11104118/
我见过很多网页都有一个简单的声音开/声音关按钮,当你按下声音时,它会播放音乐或一些 mp3 文件,当你按下声音时,它会关闭。 我该怎么做? 你好,我没打算使用 Flash -- 如果有一个标准插件我可
我正在尝试将 sound.Sound() 函数应用于循环中的 numpy 数组。具体来说,我想循环执行以下操作。 a_wave 到 d_wave 是 numpy 数组。 stim_a = sound.
我有一个项目需要我显示上传声音的波形。声音始终是 MP3,大部分时间是 22.05 kHz 单声道,只有语音。该项目是用 Flex/ActionScript 3 编写的。它旨在在浏览器中运行,但如果有
我正在尝试对 FMOD 库中的 Sound.readData 和 Sound.lock 之间的差异进行排序(我正在使用 C#/C++ 进行编程,但我会使用任何语言来回答!)。最终目标是创建波形 Vie
我在录制我的应用程序播放的系统声音时遇到问题。与“会说话的汤姆猫”iOS 应用程序类似,我的应用程序应录制屏幕视频和声音。屏幕录制和转换为视频,工作正常,问题是使用核心音频录制音频。我是第一次使用 C
我正在使用 Java 声音通过 Clip.start() 方法播放大量声音样本。 鉴于此,控制播放音量的最佳方式是什么? 特别是,我非常希望该解决方案能够跨平台可靠地工作。 最佳答案 FloatCon
我正在尝试实现一个循环播放一系列音调的应用程序。 实际上,我使用 OpenAL 并且我对这种框架的经验是积极的,因为我也可以发出声音。 这是场景: 从 CAF 文件中加载短声音(3 秒) 循环播放该声
我正在尝试使用javax.sound.sampled库中的一些类。但是,即使在我新手看来,文件就在那里,Android Studio也不会导入它们。。是不是有什么东西没放好?。AndroidStudi
当我在游戏中移动时,我的声音不是完整播放,而是循环播放几毫秒。 这是我的代码: using System.Collections; using System.Collections.Generic;
每当我在 Android 设备上的 LibGDX 游戏中播放音效时,游戏都会卡顿。我已经在三款三星设备上尝试过这款游戏: 在 Galaxy S7 Edge (2016, Android 8) 和 Ga
我创建了一个应用程序,它播放小轨道的播放列表,一切正常,直到 Windows Phone 8.1 更新 问题是 -> 轨道结束时有奇怪的滴答声” 所以我尝试在 xbox 音乐播放器中播放轨道它也有相同
我已阅读 How to use selected value of UIPickerView as time interval for notifications?一遍又一遍,但我不知道如何将答案应用
每当我使用 Java 中的 SourceDataLine 类读取构成音频的字节时,我都会在播放时听到烦人的嗡嗡声背景噪音。谁能告诉我如何才能完全摆脱它?提前致谢。 更新:我已经发布了代码,但我的实际目
这感觉像是我在这个网站上提出的第 100 个 Java Sound 相关问题,但我无法在 Java Sound API 或 jsresources.org 的任何地方找到答案。我正在制作一个多轨录音机
我已经使用 Parse.com 在我的应用程序中实现了推送通知系统,一切正常! 我唯一的问题是当通知到达时:它不播放任何声音! 我进入设置(在我的平板电脑中),在通知下,我看到了这个: 如您所见,“声
本文整理了Java中com.bugvm.sound.YSourceDataLine类的一些代码示例,展示了YSourceDataLine类的具体用法。这些代码示例主要来源于Github/Stackov
本文整理了Java中com.bugvm.sound.YTargetDataLine类的一些代码示例,展示了YTargetDataLine类的具体用法。这些代码示例主要来源于Github/Stackov
本文整理了Java中com.bugvm.sound.YNative类的一些代码示例,展示了YNative类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,
本文整理了Java中com.bugvm.sound.YClip类的一些代码示例,展示了YClip类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些
本文整理了Java中com.bugvm.sound.YLine类的一些代码示例,展示了YLine类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些
我是一名优秀的程序员,十分优秀!