Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/05/2007, 13:05
eduardo90
(Desactivado)
 
Fecha de Ingreso: julio-2006
Mensajes: 273
Antigüedad: 17 años, 9 meses
Puntos: 5
Reproductor java

Hola amigos y amigas quisiera saber si me podrian decir como puedo crear un programa para que pueda reproducir archivos con extencion .mp3 ya que solo tengo el sig. codigo que solo produce archivos .wav

import java.applet.AudioClip;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.FlowLayout;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;

public class Reproductor extends JApplet
{
private AudioClip sound1, sound2, sound3,sound4,currentSound;
private JButton playJButton, loopJButton, stopJButton;
private JComboBox soundJComboBox;

// load the image when the applet begins executing
public void init()
{
setLayout( new FlowLayout() );

String choices[] = { "Caballo","Elefante","Gallo","Oveja" };
soundJComboBox = new JComboBox( choices ); // create JComboBox

soundJComboBox.addItemListener(

new ItemListener() // anonymous inner class
{
// stop sound and change to sound to user's selection
public void itemStateChanged( ItemEvent e )
{
currentSound.stop();
currentSound = soundJComboBox.getSelectedIndex() == 0 ?
sound1 : sound2;

} // end method itemStateChanged
} // end anonymous inner class
); // end addItemListener method call

add( soundJComboBox ); // add JComboBox to applet

// set up button event handler and buttons
ButtonHandler handler = new ButtonHandler();

// create Play JButton
playJButton = new JButton( "Reproducir" );
playJButton.addActionListener( handler );
add( playJButton );

// create Loop JButton
loopJButton = new JButton( "Repetir" );
loopJButton.addActionListener( handler );
add( loopJButton );

// create Stop JButton
stopJButton = new JButton( "Detener" );
stopJButton.addActionListener( handler );
add( stopJButton );

// load sounds and set currentSound
sound1 = getAudioClip( getDocumentBase(), "Caballo.wav" );
sound2 = getAudioClip( getDocumentBase(), "Elefante.wav" );
sound3 = getAudioClip( getDocumentBase(), "Gallo.wav" );
sound4 = getAudioClip( getDocumentBase(), "Oveja.wav" );
currentSound = sound1;
} // end method init

// stop the sound when the user switches Web pages
public void stop()
{
currentSound.stop(); // stop AudioClip
} // end method stop

// private inner class to handle button events
private class ButtonHandler implements ActionListener
{
// process play, loop and stop button events
public void actionPerformed( ActionEvent actionEvent )
{
if ( actionEvent.getSource() == playJButton )
currentSound.play(); // play AudioClip once
else if ( actionEvent.getSource() == loopJButton )
currentSound.loop(); // play AudioClip continuously
else if ( actionEvent.getSource() == stopJButton )
currentSound.stop(); // stop AudioClip
} // end method actionPerformed
} // end class ButtonHandler
} // end class LoadAudioAndPlay

gracias.