2

Im trying to play a file to my speakers using AudioClip. To mention i run this on a docker container

Here i get the audio file info from my server and tried to play it.

int length = fromServer.readInt();//takes audio file length from socket
if (length > 0) {
  byte[] message = new byte[length];
  fromServer.readFully(message, 0, message.length);//reads the data in socket into array "message"

  AudioInputStream oAIS = new AudioInputStream(
  new ByteArrayInputStream(message),
  new AudioFormat(44100.0f, 16, 2, true, false),length); 
  //creates an AudioInputStream which can be used for playing the data
  AudioPlayer.main(oAIS);
 }

When my programm enters this function i get

javax.sound.sampled.LineUnavailableException
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openImpl(PulseAudioMixer.java:714)
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:588)
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:584)
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.open(PulseAudioMixer.java:579)
        at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:94)
        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)

what might be wrong? If i have to provide any other information please tell me

nemime
  • 29
  • 2
  • Don't you have opened sound file in the same time in your system? From documentation: "A LineUnavailableException is an exception indicating that a line cannot be opened because it is unavailable. This situation arises most commonly when a requested line is already in use by another application." – MrFisherman Jan 11 '21 at 13:56
  • 1
    Its not open in any other program and you are right for the documentation. I also read it but im very confused. Does it matter beacause i run it on docker? – nemime Jan 11 '21 at 14:00
  • Did you figure it out? Did you tried without docker? – MrFisherman Jan 11 '21 at 22:40
  • I've not tried playing sounds via Java within Docker, so can't comment on that aspect. But there are some questions that I have about your code. (1) On what line is the Exception thrown? (2) Is the use of JavaFX intentional? `AudioClip` is a JavaFX class and requires `MediaPlayer` for playback. (3) `AudioPlayer` is no longer supported. (4) A possible troubleshooting test might be to try a sample program from stackoverflow `javasound` tag's *info* page. https://stackoverflow.com/tags/javasound/info – Phil Freihofner Jan 12 '21 at 11:14
  • @Phil Freihofner Sorry i lost my account and im writting from my second, the exception is thrown on ```clip.open(oAIS);```. To mention i just run this code on my java IDE and it works fine. Only on docker the problem occurs – 04k Jan 12 '21 at 11:30
  • I do not see that line in the code you displayed. Can you show it in context, exactly as you have it? What Java version did you put into Docker, Java 8? If it is Java 9 or later, JavaFX is not included and must be installed separately. Regardless of whether the code happens to work on your IDE or not, you should eliminate the use of `AudioPlayer` as it is no longer supported and an unpredictable number target systems will not be able to handle it. – Phil Freihofner Jan 12 '21 at 18:31

0 Answers0