1

Im coding a music-streaming-server. So i created 2 docker containers,Client and Server. Now im trying to stream .wav file from server to client.

The following piece of code is where im trying to play the received audio data from server using AudioInputStream

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);
 }

First i tested my code on NetBeans IDE and works great. My problem is when im runing it on docker i get javax.sound.sampled.LineUnavailableException. Documentation says that 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.

Im confused because i have not opened this file on another application. What might be wrong?

madane
  • 19
  • 1
  • Is AudioPlayer a class you created or is it sun.audio.AudioPlayer? – Phil Freihofner Jan 14 '21 at 07:35
  • 1
    @PhilFreihofner i lost my account so im writing from here. I created the AudioPlayer class which includes the ```javax.sound.sampled.Clip```. and the exception accurs when im opening the clip with ```clip.open()```. Is it because docker maybe needs its own sound system? – 04k Jan 14 '21 at 11:28
  • Thanks for clarification. I wanted to rule out possibility that a deprecated class was being used. IDK if the Docker you are using has sound implemented. It might be possible to check by inspecting `AudioSystem.getMixerInfo()` and `AudioSystem.getSourceLineInfo()`. Is the Docker being used a public one from docker hub that we can inspect? – Phil Freihofner Jan 14 '21 at 17:25
  • This link is a little old, but the fact that it has a high upvote is a sign that the info has been relevant for many people. Maybe it will help. https://stackoverflow.com/questions/41083436/how-to-play-sound-in-a-docker-container – Phil Freihofner Jan 14 '21 at 17:32

0 Answers0