|
Quick Lists
|
|
Bug ID:
|
4914667
|
|
Votes
|
0
|
|
Synopsis
|
Closing and reopening MIDI IN device on Linux throws MidiUnavailableException
|
|
Category
|
java:classes_sound
|
|
Reported Against
|
tiger
|
|
Release Fixed
|
1.5(tiger-b24)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
3-Medium
|
|
Related Bugs
|
|
|
Submit Date
|
29-AUG-2003
|
|
Description
|
Using the following program, after a variable numer of iterarions, a MidiUnavailableException is thrown on the call to [MidiDevice].open().
If the try-catch block is uncommented (program sleeping for 2 seconds before the next open() call), no exception is thrown on 100 iterations.
The same problem doesn't appear at all for MIDI OUT devices.
exception:
--------
Exception in thread "main" javax.sound.midi.MidiUnavailableException: Device or resource busy
at com.sun.media.sound.MidiInDevice.nOpen(Native Method)
at com.sun.media.sound.MidiInDevice.implOpen(MidiInDevice.java:45)
at com.sun.media.sound.AbstractMidiDevice.doOpen(AbstractMidiDevice.java:116)
at com.sun.media.sound.AbstractMidiDevice.open(AbstractMidiDevice.java:88)
at OpenClose2.main(OpenClose2.java:44)
--------
program:
--------
/*
* OpenClose.java
*/
import javax.sound.midi.*;
/*
run:
java OpenClose2 100 in for 100 iterations on the MIDI IN device
java OpenClose2 16 out for 16 iterations on the MIDI OUT device
*/
public class OpenClose2 {
public static void main(String[] args) throws Exception {
int numIterations = Integer.parseInt(args[0]);
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
MidiDevice outDevice = null;
MidiDevice inDevice = null;
out("available devices:");
for (int i = 0; i < infos.length; i++) {
out(infos[i].toString());
MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
if (! (device instanceof Synthesizer)) {
if (device.getMaxReceivers() != 0) {
outDevice = device;
}
if (device.getMaxTransmitters() != 0) {
inDevice = device;
}
}
}
out("Using MIDI OUT Device: " + outDevice);
out("Using MIDI IN Device: " + inDevice);
MidiDevice testDevice = null;
if (args[1].equals("in")) {
testDevice = inDevice;
} else {
testDevice = outDevice;
}
for (int i = 0; i < numIterations; i++) {
out("@@@ ITERATION: " + i);
testDevice.open();
testDevice.close();
// with the following code uncommented, the program runs slowly,
// but without errors.
// try {
// Thread.sleep(2000);
// } catch (InterruptedException e) {
// }
}
}
private static void out(String message) {
System.out.println(message);
}
}
/*** OpenClose2.java ***/
--------
|
|
Work Around
|
Do not close Midi In devices and Transmitters while the programming is running.
|
|
Evaluation
|
xxxxx@xxxxx 2003-08-28
Maybe it has to do with the thread running inside the MidiInDevice. This is supported by the fact that a delay (allowing the thread to exit after the device is closed) seems to circumvent the bug. Furthermore, MidiOutDevice has no thread and has no such problem.
|
|
Comments
|
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |