本文整理汇总了Java中javax.sound.midi.MidiUnavailableException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java MidiUnavailableException.printStackTrace方法的具体用法?Java MidiUnavailableException.printStackTrace怎么用?Java MidiUnavailableException.printStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.midi.MidiUnavailableException
的用法示例。
在下文中一共展示了MidiUnavailableException.printStackTrace方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMidiDeviceInfo
import javax.sound.midi.MidiUnavailableException; //导入方法依赖的package包/类
/**
* Retrieve a MidiDevice.Info for a given name.
*
* This method tries to return a MidiDevice.Info whose name matches the
* passed name. If no matching MidiDevice.Info is found, null is returned.
* If bForOutput is true, then only output devices are searched, otherwise
* only input devices.
*
* @param strDeviceName
* the name of the device for which an info object should be
* retrieved.
* @param bForOutput
* If true, only output devices are considered. If false, only
* input devices are considered.
*
* @return A MidiDevice.Info object matching the passed device name or null
* if none could be found.
*/
public static MidiDevice.Info getMidiDeviceInfo(String strDeviceName,
boolean bForOutput) {
MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < aInfos.length; i++) {
if (aInfos[i].getName().contains(strDeviceName)) {
try {
MidiDevice device = MidiSystem.getMidiDevice(aInfos[i]);
boolean bAllowsInput = (device.getMaxTransmitters() != 0);
boolean bAllowsOutput = (device.getMaxReceivers() != 0);
if ((bAllowsOutput && bForOutput)
|| (bAllowsInput && !bForOutput)) {
return aInfos[i];
}
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
}
}
return null;
}
示例2: init
import javax.sound.midi.MidiUnavailableException; //导入方法依赖的package包/类
/**
* This method initializes the MusicPlayer
*/
public static boolean init()
{
try
{
if (synth == null)
synth = MidiSystem.getSynthesizer();
if (!synth.isOpen())
synth.open();
return true;
} catch (MidiUnavailableException e)
{
e.printStackTrace();
return false;
}
}
示例3: SoundPlayer
import javax.sound.midi.MidiUnavailableException; //导入方法依赖的package包/类
public SoundPlayer() {
try {
synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
midiChannel = synthesizer.getChannels()[0];
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
}
示例4: createSequencer
import javax.sound.midi.MidiUnavailableException; //导入方法依赖的package包/类
private boolean createSequencer(BufferedInputStream in) throws IOException {
if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");
// get the sequencer
try {
sequencer = MidiSystem.getSequencer( );
} catch(MidiUnavailableException me) {
if (DEBUG || Printer.err)me.printStackTrace();
return false;
}
if (sequencer==null) {
return false;
}
try {
sequence = MidiSystem.getSequence(in);
if (sequence == null) {
return false;
}
} catch (InvalidMidiDataException e) {
if (DEBUG || Printer.err)e.printStackTrace();
return false;
}
if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
return true;
}
示例5: checkAudio
import javax.sound.midi.MidiUnavailableException; //导入方法依赖的package包/类
private static void checkAudio() {
try {
if (javax.sound.midi.MidiSystem.getSequencer() == null)
System.out.println("MidiSystem sequencer unavailable.");
else if (javax.sound.sampled.AudioSystem.getMixer(null) == null)
System.out.println("AudioSystem unavailable.");
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
System.out.println("AudioSystem and MidiSystem Sequencer found.");
}
示例6: listDevicesAndExit
import javax.sound.midi.MidiUnavailableException; //导入方法依赖的package包/类
public static void listDevicesAndExit(boolean bForInput,
boolean bForOutput, boolean bVerbose) {
if (bForInput && !bForOutput) {
out("Available MIDI IN Devices:");
} else if (!bForInput && bForOutput) {
out("Available MIDI OUT Devices:");
} else {
out("Available MIDI Devices:");
}
MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < aInfos.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(aInfos[i]);
boolean bAllowsInput = (device.getMaxTransmitters() != 0);
boolean bAllowsOutput = (device.getMaxReceivers() != 0);
if ((bAllowsInput && bForInput)
|| (bAllowsOutput && bForOutput)) {
if (bVerbose) {
out("" + i + " " + (bAllowsInput ? "IN " : " ")
+ (bAllowsOutput ? "OUT " : " ")
+ aInfos[i].getName() + ", "
+ aInfos[i].getVendor() + ", "
+ aInfos[i].getVersion() + ", "
+ aInfos[i].getDescription());
} else {
out("" + i + " " + aInfos[i].getName());
}
}
} catch (MidiUnavailableException e) {
e.printStackTrace();
// device is obviously not available...
// out(e);
}
}
if (aInfos.length == 0) {
out("[No devices available]");
}
System.exit(0);
}
示例7: testDevices
import javax.sound.midi.MidiUnavailableException; //导入方法依赖的package包/类
private static boolean testDevices(MidiDevice.Info[] infos,
String providerClassName) {
boolean allOk = true;
for (int i = 0; i < infos.length; i++) {
MidiDevice device = null;
try {
device = MidiSystem.getMidiDevice(infos[i]);
} catch (MidiUnavailableException e) {
out("Exception thrown; Test NOT failed.");
e.printStackTrace(System.out);
out("");
}
out("\nTesting device: " + device);
if (device instanceof Sequencer) {
allOk &= testDevice(device, SEQUENCER_CLASS, providerClassName, true, true);
// incorrect cases
allOk &= testDevice(device, SYNTHESIZER_CLASS, providerClassName, false, false);
allOk &= testDevice(device, RECEIVER_CLASS, providerClassName, false, false);
allOk &= testDevice(device, TRANSMITTER_CLASS, providerClassName, false, false);
}
if (device instanceof Synthesizer) {
allOk &= testDevice(device, SYNTHESIZER_CLASS, providerClassName, true, true);
allOk &= testDevice(device, RECEIVER_CLASS, providerClassName, false, true);
// incorrect cases
allOk &= testDevice(device, TRANSMITTER_CLASS, providerClassName, false, false);
allOk &= testDevice(device, SEQUENCER_CLASS, providerClassName, false, false);
}
if (device instanceof Receiver) {
allOk &= testDevice(device, RECEIVER_CLASS, providerClassName, true, true);
// incorrect cases
allOk &= testDevice(device, TRANSMITTER_CLASS, providerClassName, false, false);
allOk &= testDevice(device, SYNTHESIZER_CLASS, providerClassName, false, false);
allOk &= testDevice(device, SEQUENCER_CLASS, providerClassName, false, false);
}
if (device instanceof Transmitter) {
allOk &= testDevice(device, TRANSMITTER_CLASS, providerClassName, true, true);
// incorrect cases
allOk &= testDevice(device, RECEIVER_CLASS, providerClassName, false, false);
allOk &= testDevice(device, SYNTHESIZER_CLASS, providerClassName, false, false);
allOk &= testDevice(device, SEQUENCER_CLASS, providerClassName, false, false);
}
}
return allOk;
}