lee Cancion Reproduce la cadena de audio
Server------------------Transmite al ----------------------> Cliente
lcreo que enviando bien el audio ( no estoy 100% seguro) y el gran groblema es que no se como recibirlo correctamente.
Gracias
En el servidor envio el audio asi:
Código PHP:
try {
[LEFT] File soundFile = new File("/music/song1.wav");
this.listen = new ServerSocket(this.port);
System.out.println("Web Radio Server Started on Port: " + this.port + " - bytes to transfer: " + soundFile.length() );
int i=0;
int continue_play;
byte buffer[]= new byte[250];
while(true) { // non-terminating server
this.socket = listen.accept();
/*START TRASMITION***********************************************************/
try {
this.outData = new DataOutputStream(socket.getOutputStream());
// /////////////////////////
// PREPARE Stream //
// /////////////////////////
// get audio stream
this.inData = AudioSystem.getAudioInputStream(soundFile);
System.out.println("Spiele Datei "+soundFile+" ab, client: "+i);
i++;
// get format of stream
AudioFormat audioFormat = this.inData.getFormat();
String filename = soundFile.toString();
String ext = filename.substring(filename.lastIndexOf('.') + 1,filename.length());
// check that stream is proper format
if (ext.equals("wav") && audioFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
this.inData = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, this.inData);
audioFormat = this.inData.getFormat(); // fix improper wave
// format
}
// Audioformat auslesen und kodieren und an den client schicken
System.out.println("Server Audioformat:" + audioFormat.toString());
while ((continue_play = this.inData.read(buffer, 0,buffer.length)) != -1) {
// data still left to write
if (continue_play > 0) {
// sending bytes from stream to audioplayer
//audioplayer.play(buffer, continue_play);
this.outData.write(buffer, 0, continue_play) ;
}
}
} catch (Exception error) {
JOptionPane.showMessageDialog(null, error.getMessage(), "Error!",JOptionPane.INFORMATION_MESSAGE);
error.printStackTrace();
}
/***************************************************************************/
}
}
catch (SocketException e){
System.out.println("Socket: " + e.getMessage());
}
catch (IOException e){
System.out.println("IO: " + e.getMessage());
}
catch (Exception e) {
System.out.println("FILE: " + e.getMessage());
}
finally {
if(this.socket != null){
try {
this.inData.close();
this.outData.close();
this.socket.close();
} catch (IOException e) {
System.out.println("IO: " + e.getMessage());
}
}
}[/LEFT]
y en el cliente lo trato de recibir pero no logro leer bien lo enviado:
En el cliente he tratado de leer de miles de formas esta son algunas:
Código PHP:
audioInputStream =AudioSystem.getAudioInputStream(this.socket.getInputStream());
AudioFormat audioFormat=audioInputStream.getFormat();
System.out.println("Client Audioformat:" + audioFormat.toString());
sonido=AudioSystem.getClip();
sonido.open(AudioSystem.getAudioInputStream(audioInputStream));
sonido.start();
Código PHP:
audioInputStream=AudioSystem.getAudioInputStream(this.socket.getInputStream());
AudioFormat audioFormat=audioInputStream.getFormat();
System.out.println("Client Audioformat:" + audioFormat.toString());
SourceDataLine sourceDataLine=null;
DataLine.Info info=new DataLine.Info(SourceDataLine.class,audioFormat);
try {
sourceDataLine=(SourceDataLine)AudioSystem.getLine(info);
sourceDataLine.open();
sourceDataLine.start();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
Código PHP:
Play_Audio audioplayer = new Play_Audio();
audioplayer.init(rate, sizeInBits,channels, true,bigEndian);
this.inData.readLine();
System.out.println( inData.readLine());
while(true) { // close dialogue
String message = inData.readLine();
if(message==null)
break;
try {
audioInputStream = AudioSystem.getAudioInputStream(this.inData);
} catch (UnsupportedAudioFileException e) {
System.out.println("Tipo de archivo no soportado...");
}
//audioplayer.play(message, message.length());
}
Agradezco su respuesta