在Ubuntu上通过PulseAudio从Java播放音频文件时

在Ubuntu上通过PulseAudio从Java播放音频文件时

本文介绍了在Ubuntu上通过PulseAudio从Java播放音频文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

shell上的消息是:

 线程main中的异常java.lang.IllegalArgumentException:格式无效
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.createStream(PulseAudioDataLine.java:142)
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:99)
at org .classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:283)
at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:402)
at org.classpath.icedtea .pulseaudio.PulseAudioClip.open(PulseAudioClip.java:453)
at reprod.ReproducirFichero(reprod.java:16)
at reprod.main(reprod.java:44)

我尝试下载音频的新驱动程序,我尝试重新安装openJDK 7和openJRE 7,我也尝试安装java 7. / p>

我已经在另一台计算机上证明了我的代码并且它有效,我使用的台式机主板是intel d525mw,音频形式在我试图玩的是.wav。我使用的linux版本是Ubuntu 12.04.3。请给我帮忙。谢谢



这里是派对的我的代码,我尝试播放.wav音频格式

  import javax.sound.sampled。*; 

public class reprod {

public static void play(){
try {
Clip cl = AudioSystem.getClip();

文件f =新文件(/ home / usr / Desktop / d.wav);
AudioInputStream ais = AudioSystem.getAudioInputStream(f);

cl.open(ais);

cl.start();
System.out.println(播放......);

while(cl.isRunning())
Thread.sleep(4000);


cl.close();

我使用的linux版本是Ubuntu 12.04.3

解决方案

我通过简单地将参数 null 传递给 AudioSystem.getClip解决了这个问题( )



我不知道为什么会发生这种异常,我之前在Windows上运行这个项目,它起作用了......之后Linux和这里,它没有用。


The message on the shell is:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid format
    at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.createStream(PulseAudioDataLine.java:142)
    at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:99)
    at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:283)
    at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:402)
    at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:453)
    at reprod.ReproducirFichero(reprod.java:16)
    at reprod.main(reprod.java:44)

I try to download new drivers for audio, i try to reinstall openJDK 7 and openJRE 7 and also i try to install java 7.

I have proved my code in another computer and it works, the desktop board that i use is an intel d525mw, the audio format that i´m trying to play is .wav.The version of linux that I use is Ubuntu 12.04.3.Please I need help.Thanks

here is party of my code, and i try to play a .wav audio format

import javax.sound.sampled.*;

public class reprod {

public static void play(){
    try {
        Clip cl = AudioSystem.getClip();

        File f = new File("/home/usr/Desktop/d.wav");
        AudioInputStream ais = AudioSystem.getAudioInputStream(f);

        cl.open(ais);

        cl.start();
        System.out.println("playing...");

        while (cl.isRunning())
            Thread.sleep(4000);


        cl.close();

the version of linux that I use is Ubuntu 12.04.3

解决方案

I solved the problem by simply passing the parameter null into AudioSystem.getClip().

I don't know why this exception occured, I run this project before on Windows, and it worked... After on Linux and here, it didn't work.

这篇关于在Ubuntu上通过PulseAudio从Java播放音频文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 08:52