"JAVA" Como pausar clips .WAV y otras cosas help!

xetsus

Lanero Novato
8 Mar 2009
1
Hola :D quisiera saber como puedo pausar un archivo wav y despues dandole click de nuevo como puedo resumirlo, como si fuese en winamp... y la otra cosa es que mas tengo que implementar para que programa lea archivos en formato mp3. de antemano muchas gracias

/*Creado por Sanchez Diaz Jorge
*Fecha de creacion 07/marzo/2009
*/
package ejemplosJswim;
//imports
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.sound.sampled.*;
import javax.sound.sampled.Clip;
import javax.sound.*;
public class repMusical
{
public static void main(String[] args)
{
JFrame rpPantalla = new lawlFrame();
rpPantalla.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
rpPantalla.setVisible(true);
}
}
class lawlFrame extends JFrame
{
final JButton btnPlay = new JButton ("Play");
final JButton btnStop = new JButton ("Stop");
final JButton btnPause = new JButton ("Pausa");
final JButton btnRepeat = new JButton ("Repeat");
ImageIcon icPlay = new ImageIcon("Play.png");
ImageIcon icStop = new ImageIcon("stop.png");
ImageIcon icPause = new ImageIcon("pause.png");
ImageIcon icRepeat = new ImageIcon("repeat.png");
public lawlFrame()
{
setTitle("Reproductor");
setLayout(null);
setSize(ancho, largo);
selector = new JFileChooser();
selector.setCurrentDirectory(new File("."));
btnPlay.setSize(100, 40);
btnPlay.setLocation(20, 100);
btnPlay.setIcon(icPlay);
btnPlay.setToolTipText( "Presione para reproducir" );
btnPause.setSize(100, 40);
btnPause.setLocation(140, 100);
btnPause.setIcon(icPause);
btnPause.setToolTipText( "Presiona para pausar" );
btnStop.setSize(100, 40);
btnStop.setLocation(260, 100);
btnStop.setIcon(icStop);
btnStop.setToolTipText( "Presiona para parar" );
btnRepeat.setSize(100, 40);
btnRepeat.setLocation(380, 100);
btnRepeat.setIcon(icRepeat);
btnRepeat.setToolTipText( "Presiona para reproduccion continua." );
add(btnPlay);
add(btnPause);
add(btnStop);
add(btnRepeat);
btnPlay.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent x)
{
int choser = selector.showOpenDialog(null);
if (choser == JFileChooser.APPROVE_OPTION)
{
String path = selector.getSelectedFile().getPath();
try
{
aReproducir=AudioSystem.getClip();
aReproducir.open(AudioSystem.getAudioInputStream(new File(path)));
aReproducir.start();
}
catch (Exception fallo)
{
System.out.println(fallo);
}
}
}
});
btnStop.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent x)
{
aReproducir.stop();
}
}
);
btnRepeat.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent x)
{
aReproducir.loop(Clip.LOOP_CONTINUOUSLY);
}
}
);
btnPause.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent x)
{
//no se que poner T_T gracias =D
}
}
);
JMenuBar menBarra = new JMenuBar();
setJMenuBar(menBarra);
JMenu mFile = new JMenu("Archivo");
menBarra.add(mFile);
JMenuItem iOpen = new JMenuItem("Abrir");
mFile.add(iOpen);
JMenuItem iClose = new JMenuItem("Cerrar");
mFile.add(iClose);
iClose.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){System.exit(0);}});
iOpen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent x)
{
int choser = selector.showOpenDialog(null);
if (choser == JFileChooser.APPROVE_OPTION)
{
path = selector.getSelectedFile().getPath();

try
{
aReproducir=AudioSystem.getClip();
aReproducir.open(AudioSystem.getAudioInputStream(new File(path)));
aReproducir.start();
}
catch (Exception fallo)
{
System.out.println(fallo);
}
}
}
});
}
public long donde;
private String path;
private javax.sound.sampled.Clip aReproducir;
private JFileChooser selector;
private static final int largo = 300;
private static final int ancho = 510;
}

y que mas tengo que agregar para que mi programa lea los mp3 con el filechooser y los cargue como si fuesen los wav :O de antemano muchas gracias.