Da questo listato non riesco a sentire il file che vorrei:
Mi da questo errore:
could not get sequence from file
null.
Presumo sia l'istruzione:
currentSound = MidiSystem.getSequence(file);
Forse il formato del file non è giusto?Grazie
Codice:
import javax.swing.*;
import javax.sound.midi.*;
import java.awt.GridLayout;
import java.io.File;
import javax.sound.midi.*;
public class PlayMidi1 extends JFrame {
String song="set_fire1.wav";
PlayMidi1() {
super("Play MIDI Files");
setSize(180, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MidiPanel1 midi = new MidiPanel1(song);
JPanel pane = new JPanel();
pane.add(midi);
setContentPane(pane);
setVisible(true);
}
public static void main(String[] args) {
PlayMidi1 pm = new PlayMidi1();
}
}
class MidiPanel1 extends JPanel implements Runnable {
Thread runner;
JProgressBar progress = new JProgressBar();
Sequence currentSound;
Sequencer player;
String songFile;
MidiPanel1(String song) {
super();
songFile = song;
JLabel label = new JLabel("Playing file ...");
setLayout(new GridLayout(2, 1));
add(label);
add(progress);
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void run() {
try {
File file = new File("set_fire1.wav");
currentSound = MidiSystem.getSequence(file);
player = MidiSystem.getSequencer();
player.open();
player.setSequence(currentSound);
progress.setMinimum(0);
progress.setMaximum((int)player.getMicrosecondLength());
player.start();
while (player.isRunning()) {
progress.setValue((int)player.getMicrosecondPosition());
try {
Thread.sleep(1000);
} catch (Exception e) {e.printStackTrace(); }
}
progress.setValue((int)player.getMicrosecondPosition());
player.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
System.out.println(currentSound);
}
}
}
Mi da questo errore:
could not get sequence from file
null.
Presumo sia l'istruzione:
currentSound = MidiSystem.getSequence(file);
Forse il formato del file non è giusto?Grazie