You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.2 KiB
83 lines
2.2 KiB
8 years ago
|
package org.libresonic.player.service.jukebox;
|
||
8 years ago
|
|
||
|
import javax.swing.*;
|
||
|
import javax.swing.event.ChangeEvent;
|
||
|
import javax.swing.event.ChangeListener;
|
||
8 years ago
|
|
||
8 years ago
|
import java.awt.*;
|
||
|
import java.awt.event.ActionEvent;
|
||
|
import java.awt.event.ActionListener;
|
||
|
import java.io.FileInputStream;
|
||
|
|
||
|
/**
|
||
|
* @author Sindre Mehus
|
||
|
* @version $Id$
|
||
|
*/
|
||
|
public class PlayerTest implements AudioPlayer.Listener {
|
||
|
|
||
|
private AudioPlayer player;
|
||
|
|
||
|
public PlayerTest() throws Exception {
|
||
|
createGUI();
|
||
|
}
|
||
|
|
||
|
private void createGUI() {
|
||
|
JFrame frame = new JFrame();
|
||
|
|
||
|
JButton startButton = new JButton("Start");
|
||
|
JButton stopButton = new JButton("Stop");
|
||
|
JButton resetButton = new JButton("Reset");
|
||
|
final JSlider gainSlider = new JSlider(0, 1000);
|
||
|
|
||
|
startButton.addActionListener(new ActionListener() {
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
createPlayer();
|
||
|
player.play();
|
||
|
}
|
||
|
});
|
||
|
stopButton.addActionListener(new ActionListener() {
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
player.pause();
|
||
|
}
|
||
|
});
|
||
|
resetButton.addActionListener(new ActionListener() {
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
player.close();
|
||
|
createPlayer();
|
||
|
}
|
||
|
});
|
||
|
gainSlider.addChangeListener(new ChangeListener() {
|
||
|
public void stateChanged(ChangeEvent e) {
|
||
|
float gain = (float) gainSlider.getValue() / 1000.0F;
|
||
|
player.setGain(gain);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
frame.setLayout(new FlowLayout());
|
||
|
frame.add(startButton);
|
||
|
frame.add(stopButton);
|
||
|
frame.add(resetButton);
|
||
|
frame.add(gainSlider);
|
||
|
|
||
|
frame.pack();
|
||
|
frame.setVisible(true);
|
||
|
}
|
||
|
|
||
|
private void createPlayer() {
|
||
|
try {
|
||
|
player = new AudioPlayer(new FileInputStream("/Users/sindre/Downloads/sample.au"), this);
|
||
|
} catch (Exception e) {
|
||
|
throw new RuntimeException(e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) throws Exception {
|
||
|
new PlayerTest();
|
||
|
}
|
||
|
|
||
|
public void stateChanged(AudioPlayer player, AudioPlayer.State state) {
|
||
|
System.out.println(state);
|
||
|
}
|
||
|
}
|
||
|
|