为什么线程不结束

jun573 2006-04-27 12:30:13
这个是获取声音文件长度的函数,在main中调用 时线程不会结束,为什么
public static double getLength(String path)throws Exception{
AudioInputStream stream;
stream = AudioSystem.getAudioInputStream(new URL(path));
// 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()*2,
format.getChannels(),
format.getFrameSize()*2,
format.getFrameRate(),
true); // big endian
stream = AudioSystem.getAudioInputStream(format, stream);
}
// Create the clip
DataLine.Info info = new DataLine.Info(
Clip.class, stream.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
// This method does not return until the audio file is completely loaded
//clip.open(stream);
clip.stop();
clip.close();
return clip.getBufferSize() /(clip.getFormat().getFrameSize() * clip.getFormat().getFrameRate());
}



...全文
219 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jun573 2006-04-29
  • 打赏
  • 举报
回复
http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4735740
在这找到这是个bug谁能帮我写出解决的代码
fenghuangling 2006-04-28
  • 打赏
  • 举报
回复
帮你顶一下
netsummer123 2006-04-28
  • 打赏
  • 举报
回复
使用available
if(stream.available>0){
stream = AudioSystem.getAudioInputStream(new URL(path));}
jun573 2006-04-28
  • 打赏
  • 举报
回复
那应该怎么处理呢?
我用main()调用的可以取得声音文件的长度,按理说应该取到了数据啊
UnAgain 2006-04-27
  • 打赏
  • 举报
回复
mark
windforce9811 2006-04-27
  • 打赏
  • 举报
回复
I/O阻塞了
线程在等待声音数据。没有结束之前一直在执行。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧