Foros del Web » Programación para mayores de 30 ;) » Java »

Webradio por Sockets -- audioInputStream

Estas en el tema de Webradio por Sockets -- audioInputStream en el foro de Java en Foros del Web. Tengo que desarrolar para la clase de maniana una pequena muestra de como funcionan un servidor de sockets que envia musica a sus respectivos clientes. ...
  #1 (permalink)  
Antiguo 02/11/2009, 19:53
 
Fecha de Ingreso: junio-2007
Ubicación: por ahi
Mensajes: 262
Antigüedad: 16 años, 10 meses
Puntos: 4
Webradio por Sockets -- audioInputStream

Tengo que desarrolar para la clase de maniana una pequena muestra de como funcionan un servidor de sockets que envia musica a sus respectivos clientes.

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_SIGNEDthis.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(buffer0,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(buffer0continue_play) ;
                        }
                    }
                        
                } catch (
Exception error) {
                      
JOptionPane.showMessageDialog(nullerror.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(ratesizeInBits,channelstrue,bigEndian);
            
this.inData.readLine();
            
System.out.printlninData.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
__________________
Hernando Saenz Sanchez

Última edición por hernandos; 02/11/2009 a las 22:54
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:08.