Skip to content

Instantly share code, notes, and snippets.

@akameco
Last active August 29, 2015 14:12
Show Gist options
  • Save akameco/53b5538bcf319d5abd38 to your computer and use it in GitHub Desktop.
Save akameco/53b5538bcf319d5abd38 to your computer and use it in GitHub Desktop.
mp3再生
import javazoom.jlgui.basicplayer.BasicPlayer;
import javazoom.jlgui.basicplayer.BasicPlayerException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
public class SamplePlayer extends JPanel {
BasicPlayer player;
public SamplePlayer() {
super(new BorderLayout());
player = new BasicPlayer();
JTextField tf = new JTextField();
add(tf,BorderLayout.NORTH);
add(new JButton(new AbstractAction("再生") {
@Override
public void actionPerformed(ActionEvent e) {
try {
player.open(new File(tf.getText()));
player.play();
} catch (BasicPlayerException e1) {
e1.printStackTrace();
}
}
}));
}
public static void main(String[] args) {
JFrame w = new JFrame();
w.add(new SamplePlayer());
w.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
w.setSize(200, 100);
w.setVisible(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment