错误而在Java播放声音 [英] Error while playing sound in Java

查看:1118
本文介绍了错误而在Java播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Java应用程序播放声音,但我每次调用方法时,我得到这个异​​常: javax.sound.sampled.LineUnavailableException:与格式线PCM_SIGNED 48000.0赫兹,24位,单声道,3个字节/帧,不支持little-endian的。

I'm trying to play a sound in my Java Application, but every time I call the method I get this exception: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 24 bit, mono, 3 bytes/frame, little-endian not supported.

这里的code:

    AudioInputStream audio = AudioSystem.getAudioInputStream(new File("src/media/ding2.wav"));
    Clip clip = AudioSystem.getClip();  
    clip.open(audio);
    clip.start();

我试图传递一个URL播放文件,它工作正常,但我的ding2.wav没有什么工作。

I tried to play a file by passing a URL and it works fine, but with my "ding2.wav" nothing works.

在此先感谢您的帮助。

推荐答案

通过查看过的在机制的文档这里的LineUnavailableException,即当行不可用,或请求的资源正在使用由其他应用程序,

By looking over HERE in Documention, the LineUnavailableException arises when the line is not Available, or the requested resource is in use by Another Application,

请确保您的音频文件是不是在任何其他应用程序中打开。

Make Sure that your audio file is not open in any other application.

修改

由于错误消息指出:与格式线PCM_SIGNED 48000.0赫兹,24位,单声道,3个字节/帧
你所提供的文件格式不支持。
正如你所说的我试图传递一个URL播放文件,它工作正常,
把旧的文件回来,通过检查文件格式

As the error message says :line with format PCM_SIGNED 48000.0 Hz, 24 bit, mono, 3 bytes/frame the file format you are providing is not supported. and as you said I tried to play a file by passing a URL and it works fine, put the Old file back and check the file format by using

System.out.println(audio.getFormat());

和检查什么是该文件的文件格式,这是否是相同的与格式上述_line PCM_SIGNED 48000.0赫兹,24位,单声道,3 _与否,

and check what was the file format of that file , whether that was same to the above _line with format PCM_SIGNED 48000.0 Hz, 24 bit, mono, 3 _ or not,

这篇关于错误而在Java播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆