Reproducción de archivos de audio.
Hola, me gustarÃa saber como reproducir archivos de audio.
Busqué en la API y encontré la interface audioClip, pero no entendà como hay que hacer para reproducir el archivo. Además no sé como marcar el archivo que quiero reproducir.
Existe alguna otra forma de reproducir archivos de audio o es esta la única?
Muchas gracias.
Busqué en la API y encontré la interface audioClip, pero no entendà como hay que hacer para reproducir el archivo. Además no sé como marcar el archivo que quiero reproducir.
Existe alguna otra forma de reproducir archivos de audio o es esta la única?
Muchas gracias.
Mira la clase AudioClip es necesaria para poder ejecutar un archivo de sonido(solamente reproduce archivos con la extencion *.au), Primero declaras un compponente tipo AudioClip, despues le asignas el archivo de audio(ya sea por parametro o con un URL)
por decir AudiClip sonido; y despues asiganarle el archivo, o bien directamente conesta instruccion play(URL,"archivo.au"); si le asignaste el archivo a un componente Audio clip bastara con esto
sonido.play(); o sonido.stop(); o sonido.loop();
por decir AudiClip sonido; y despues asiganarle el archivo, o bien directamente conesta instruccion play(URL,"archivo.au"); si le asignaste el archivo a un componente Audio clip bastara con esto
sonido.play(); o sonido.stop(); o sonido.loop();
Para quien le interese todo eso se puede conseguir mediante el paquete javax.sound (integrado en la jdk1.4.1), reproduce wav y midi, aunque no lo hace con mp3 (aunque en teoria se puede usar un plugin para ello), pero no es algo inmediato.
Os recomiendo leer en http://java.sun.com/ las API'S de java
Os recomiendo leer en http://java.sun.com/ las API'S de java
Para esto debes utilizar la clase AudioClip, unque esta solo reproduce archivos *.au esto no es problema, ya que puedes encotrar convertidores de mp3 o wav a *.au.
aa un componente AudioClip,le asignas el archivo *.au, mediante un parametro o con un URL
por decir AudiClip soni;si no asignaste el archivo entonces necesitas poner la siguiente instruccion:
play(URL,"cancion.au");
y si si asignaste el archivo solo necesitas las siguientes instrucciones
soni.play(); //reproduce una sola ves
sonido.stop(); //detiene la reproduccion
sonido.loop(); //reproduce varias veces
aa un componente AudioClip,le asignas el archivo *.au, mediante un parametro o con un URL
por decir AudiClip soni;si no asignaste el archivo entonces necesitas poner la siguiente instruccion:
play(URL,"cancion.au");
y si si asignaste el archivo solo necesitas las siguientes instrucciones
soni.play(); //reproduce una sola ves
sonido.stop(); //detiene la reproduccion
sonido.loop(); //reproduce varias veces
quiero saber como hacer para escuchar o reproducir archivos wav tipo mensaje o advertencia en lenguaje c o java.
garacias.
garacias.
Este código es de un applet que reproduce sonidos, espero que te sirva
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/**
* Insert the type's description here.
* Creation date: (19/09/2001 18:08:08)
* @author: Administrator
*/
public class Sonidos extends Applet implements MouseListener {
public java.applet.AudioClip sonido, sonido1, sonido2;
/**
* Returns information about this applet.
* @return a string of information about this applet
*/
public String getAppletInfo() {
return "Sonidosn" +
"n" +
"Insert the type's description here.n" +
"Creation date: (19/09/2001 18:08:08)n" +
"@author: Administratorn" +
"";
}
/**
* Initializes the applet.
*/
public void init() {
super.init();
addMouseListener(this);
sonido=getAudioClip (getCodeBase(),"cuckoo.au");
sonido1=getAudioClip (getCodeBase(),"first.au");
sonido2=getAudioClip (getCodeBase(),"second.au");
}
/**
* Called when the mouse has been clicked.
* @param e the received event
*/
public void mouseClicked(MouseEvent e) {
System.out.println("mouseClicked");
}
/**
* Called when the mouse has entered a window.
* @param e the received event
*/
public void mouseEntered(MouseEvent e) {
System.out.println("mouseEntered");
sonido.play();
}
/**
* Called when the mouse has exited a window.
* @param e the received event
*/
public void mouseExited(MouseEvent e) {
System.out.println("mouseExited");
sonido2.play();
}
/**
* Called when a mouse button has been pressed.
* @param e the received event
*/
public void mousePressed(MouseEvent e) {
System.out.println("mousePressed");
sonido1.play();
}
/**
* Called when a mouse button has been released.
* @param e the received event
*/
public void mouseReleased(MouseEvent e) {
System.out.println("mouseReleased");
}
/**
* Paints the applet.
* If the applet does not need to be painted (e.g. if it is only a container for other
* awt components) then this method can be safely removed.
*
* @param g the specified Graphics window
* @see #update
*/
public void paint(Graphics g) {
super.paint(g);
// insert code to paint the applet here
}
/**
* Called to start the applet. You never need to call this method
* directly, it is called when the applet's document is visited.
* @see #init
* @see #stop
* @see #destroy
*/
public void start() {
super.start();
sonido.play();
// insert any code to be run when the applet starts here
}
/**
* Called to stop the applet. It is called when the applet's document is
* no longer on the screen. It is guaranteed to be called before destroy()
* is called. You never need to call this method directly.
* @see #init
* @see #start
* @see #destroy
*/
public void stop() {
super.stop();
// insert any code to be run when the applet is stopped here
}
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/**
* Insert the type's description here.
* Creation date: (19/09/2001 18:08:08)
* @author: Administrator
*/
public class Sonidos extends Applet implements MouseListener {
public java.applet.AudioClip sonido, sonido1, sonido2;
/**
* Returns information about this applet.
* @return a string of information about this applet
*/
public String getAppletInfo() {
return "Sonidosn" +
"n" +
"Insert the type's description here.n" +
"Creation date: (19/09/2001 18:08:08)n" +
"@author: Administratorn" +
"";
}
/**
* Initializes the applet.
*/
public void init() {
super.init();
addMouseListener(this);
sonido=getAudioClip (getCodeBase(),"cuckoo.au");
sonido1=getAudioClip (getCodeBase(),"first.au");
sonido2=getAudioClip (getCodeBase(),"second.au");
}
/**
* Called when the mouse has been clicked.
* @param e the received event
*/
public void mouseClicked(MouseEvent e) {
System.out.println("mouseClicked");
}
/**
* Called when the mouse has entered a window.
* @param e the received event
*/
public void mouseEntered(MouseEvent e) {
System.out.println("mouseEntered");
sonido.play();
}
/**
* Called when the mouse has exited a window.
* @param e the received event
*/
public void mouseExited(MouseEvent e) {
System.out.println("mouseExited");
sonido2.play();
}
/**
* Called when a mouse button has been pressed.
* @param e the received event
*/
public void mousePressed(MouseEvent e) {
System.out.println("mousePressed");
sonido1.play();
}
/**
* Called when a mouse button has been released.
* @param e the received event
*/
public void mouseReleased(MouseEvent e) {
System.out.println("mouseReleased");
}
/**
* Paints the applet.
* If the applet does not need to be painted (e.g. if it is only a container for other
* awt components) then this method can be safely removed.
*
* @param g the specified Graphics window
* @see #update
*/
public void paint(Graphics g) {
super.paint(g);
// insert code to paint the applet here
}
/**
* Called to start the applet. You never need to call this method
* directly, it is called when the applet's document is visited.
* @see #init
* @see #stop
* @see #destroy
*/
public void start() {
super.start();
sonido.play();
// insert any code to be run when the applet starts here
}
/**
* Called to stop the applet. It is called when the applet's document is
* no longer on the screen. It is guaranteed to be called before destroy()
* is called. You never need to call this method directly.
* @see #init
* @see #start
* @see #destroy
*/
public void stop() {
super.stop();
// insert any code to be run when the applet is stopped here
}
}
este programa que nos diste le podrias realizar para hacerlo correr en un servlet o tienes uno hecho
porfavor me lo puedes enviar a mi mail te lo agradeceria mucho
gracias si no te sale mi mail aqui te lo envio
[email protected]
porfavor me lo puedes enviar a mi mail te lo agradeceria mucho
gracias si no te sale mi mail aqui te lo envio
[email protected]
haber si te sirve este ejemplo...
es un applet con botones para reproducir y parar los sonidos
public class LoadAudioPlay extends Applet{
private AudioClip sound;
private Button playSound, loopSound, stopSound;
public void init()
{
sound = getAudioClip(getDocumentBase(),”hi.au”);
playSound=new Button(“Play”);
loopSound=new Button(“Ciclo”);
stopSound=new Button(“Alto”);
add(playSound);
add(loopSound);
add(stopSound);
}
public Boolean action (Event e, Object o)
{
if (e.target==playSound)
sound.play();
else if (e.target==loopSound)
sound.loop();
else if(e.target==stopSound)
sound.stop();
return true;
}
}
importante solo puedes usar archivos .au
play(); lo toca una vez
stop(); es para hacer alto
loop(); es como un ciclo, termina y vuelve a empezar
es un applet con botones para reproducir y parar los sonidos
public class LoadAudioPlay extends Applet{
private AudioClip sound;
private Button playSound, loopSound, stopSound;
public void init()
{
sound = getAudioClip(getDocumentBase(),”hi.au”);
playSound=new Button(“Play”);
loopSound=new Button(“Ciclo”);
stopSound=new Button(“Alto”);
add(playSound);
add(loopSound);
add(stopSound);
}
public Boolean action (Event e, Object o)
{
if (e.target==playSound)
sound.play();
else if (e.target==loopSound)
sound.loop();
else if(e.target==stopSound)
sound.stop();
return true;
}
}
importante solo puedes usar archivos .au
play(); lo toca una vez
stop(); es para hacer alto
loop(); es como un ciclo, termina y vuelve a empezar
claro que el uso de archivos de sonido depende de la versión de java que uses, algunas solo soportan .au