Skip to content

Instantly share code, notes, and snippets.

@akameco
Last active Aug 29, 2015
Embed
What would you like to do?
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