Java 怎么请求MIDI设备

2019年7月29日20:06:52Java 怎么请求MIDI设备已关闭评论 389 704字阅读2分20秒

1.简介

Java 怎么请求MIDI设备?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

 

import java.util.Scanner;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;

public class Main {
    public static MidiDevice askForMidiDevice() {
        try {
            System.out.println("Available MIDI Devices:");
            MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
            for (int i = 0; i < infos.length; i++) {
                System.out.println("  " + i + ". " + infos[i].getName()
                        + " - " + infos[i].getDescription());
            }
            System.out
                    .print("Enter the number of the device you want to use: ");
            Scanner scanner = new Scanner(System.in);
            int a = scanner.nextInt();

            return MidiSystem.getMidiDevice(infos[a]);
        } catch (MidiUnavailableException e) {
            e.printStackTrace();
        }
        return null;
    }
}

 
编程十万个怎么办