类android.media.midi.MidiDeviceInfo源码实例Demo

下面列出了怎么用android.media.midi.MidiDeviceInfo的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: media-samples   文件: MidiPrinter.java
public static String formatDeviceInfo(MidiDeviceInfo info) {
    StringBuilder sb = new StringBuilder();
    if (info != null) {
        Bundle properties = info.getProperties();
        for (String key : properties.keySet()) {
            Object value = properties.get(key);
            sb.append(key).append(" = ").append(value).append('\n');
        }
        for (PortInfo port : info.getPorts()) {
            sb.append((port.getType() == PortInfo.TYPE_INPUT) ? "input" : "output")
                    .append("[")
                    .append(port.getPortNumber())
                    .append("] = \"")
                    .append(port.getName()).append("\"\n");
        }
    }
    return sb.toString();
}
 
源代码2 项目: media-samples   文件: MidiInputPortSelector.java
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    close();
    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mInputPort = mOpenDevice.openInputPort(
                            wrapper.getPortIndex());
                    if (mInputPort == null) {
                        Log.e(MidiConstants.TAG, "could not open input port on " + info);
                    }
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openInputPort might take a while.
    }
}
 
源代码3 项目: android-MidiScope   文件: MidiPortWrapper.java
private void updateString() {
    if (mInfo == null) {
        mString = "- - - - - -";
    } else {
        StringBuilder sb = new StringBuilder();
        String name = mInfo.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_NAME);
        if (name == null) {
            name = mInfo.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER) + ", "
                    + mInfo.getProperties()
                            .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
        }
        sb.append("#" + mInfo.getId());
        sb.append(", ").append(name);
        PortInfo portInfo = findPortInfo();
        sb.append("[" + mPortIndex + "]");
        if (portInfo != null) {
            sb.append(", ").append(portInfo.getName());
        } else {
            sb.append(", null");
        }
        mString = sb.toString();
    }
}
 
源代码4 项目: media-samples   文件: MidiTools.java
/**
 * @return a device that matches the manufacturer and product or null
 */
public static MidiDeviceInfo findDevice(MidiManager midiManager,
        String manufacturer, String product) {
    for (MidiDeviceInfo info : midiManager.getDevices()) {
        String deviceManufacturer = info.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER);
        if ((manufacturer != null)
                && manufacturer.equals(deviceManufacturer)) {
            String deviceProduct = info.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
            if ((product != null) && product.equals(deviceProduct)) {
                return info;
            }
        }
    }
    return null;
}
 
源代码5 项目: media-samples   文件: MidiPortWrapper.java
private void updateString() {
    if (mInfo == null) {
        mString = "- - - - - -";
    } else {
        StringBuilder sb = new StringBuilder();
        String name = mInfo.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_NAME);
        if (name == null) {
            name = mInfo.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER) + ", "
                    + mInfo.getProperties()
                            .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
        }
        sb.append("#" + mInfo.getId());
        sb.append(", ").append(name);
        PortInfo portInfo = findPortInfo();
        sb.append("[" + mPortIndex + "]");
        if (portInfo != null) {
            sb.append(", ").append(portInfo.getName());
        } else {
            sb.append(", null");
        }
        mString = sb.toString();
    }
}
 
源代码6 项目: media-samples   文件: MidiInputPortSelector.java
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    close();
    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mInputPort = mOpenDevice.openInputPort(
                            wrapper.getPortIndex());
                    if (mInputPort == null) {
                        Log.e(MidiConstants.TAG, "could not open input port on " + info);
                    }
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openInputPort might take a while.
    }
}
 
源代码7 项目: media-samples   文件: MidiTools.java
/**
 * @return a device that matches the manufacturer and product or null
 */
public static MidiDeviceInfo findDevice(MidiManager midiManager,
        String manufacturer, String product) {
    for (MidiDeviceInfo info : midiManager.getDevices()) {
        String deviceManufacturer = info.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER);
        if ((manufacturer != null)
                && manufacturer.equals(deviceManufacturer)) {
            String deviceProduct = info.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
            if ((product != null) && product.equals(deviceProduct)) {
                return info;
            }
        }
    }
    return null;
}
 
源代码8 项目: media-samples   文件: MidiPortWrapper.java
private void updateString() {
    if (mInfo == null) {
        mString = "- - - - - -";
    } else {
        StringBuilder sb = new StringBuilder();
        String name = mInfo.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_NAME);
        if (name == null) {
            name = mInfo.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER) + ", "
                    + mInfo.getProperties()
                            .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
        }
        sb.append("#" + mInfo.getId());
        sb.append(", ").append(name);
        PortInfo portInfo = findPortInfo();
        sb.append("[" + mPortIndex + "]");
        if (portInfo != null) {
            sb.append(", ").append(portInfo.getName());
        } else {
            sb.append(", null");
        }
        mString = sb.toString();
    }
}
 
源代码9 项目: android-midisuite   文件: MidiTools.java
/**
 * @return a device that matches the manufacturer and product or null
 */
public static MidiDeviceInfo findDevice(MidiManager midiManager,
        String manufacturer, String product) {
    for (MidiDeviceInfo info : midiManager.getDevices()) {
        String deviceManufacturer = info.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER);
        if ((manufacturer != null)
                && manufacturer.equals(deviceManufacturer)) {
            String deviceProduct = info.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
            if ((product != null) && product.equals(deviceProduct)) {
                return info;
            }
        }
    }
    return null;
}
 
源代码10 项目: android-MidiSynth   文件: MidiInputPortSelector.java
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    close();
    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mInputPort = mOpenDevice.openInputPort(
                            wrapper.getPortIndex());
                    if (mInputPort == null) {
                        Log.e(MidiConstants.TAG, "could not open input port on " + info);
                    }
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openInputPort might take a while.
    }
}
 
源代码11 项目: android-midisuite   文件: MidiPortWrapper.java
private void updateString() {
    if (mInfo == null) {
        mString = "- - - - - -";
    } else {
        StringBuilder sb = new StringBuilder();
        String name = mInfo.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_NAME);
        if (name == null) {
            name = mInfo.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER) + ", "
                    + mInfo.getProperties()
                            .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
        }
        sb.append("#" + mInfo.getId());
        sb.append(", ").append(name);
        PortInfo portInfo = findPortInfo();
        sb.append("[" + mPortIndex + "]");
        if (portInfo != null) {
            sb.append(", ").append(portInfo.getName());
        } else {
            sb.append(", null");
        }
        mString = sb.toString();
    }
}
 
源代码12 项目: android-midisuite   文件: MidiDeviceMonitor.java
@Override
public void onDeviceAdded(final MidiDeviceInfo device) {
    // Call all of the locally registered callbacks.
    for(Map.Entry<DeviceCallback, Handler> item : mCallbacks.entrySet()) {
        final DeviceCallback callback = item.getKey();
        Handler handler = item.getValue();
        if(handler == null) {
            callback.onDeviceAdded(device);
        } else {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    callback.onDeviceAdded(device);
                }
            });
        }
    }
}
 
源代码13 项目: android-MidiSynth   文件: MidiTools.java
/**
 * @return a device that matches the manufacturer and product or null
 */
public static MidiDeviceInfo findDevice(MidiManager midiManager,
        String manufacturer, String product) {
    for (MidiDeviceInfo info : midiManager.getDevices()) {
        String deviceManufacturer = info.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER);
        if ((manufacturer != null)
                && manufacturer.equals(deviceManufacturer)) {
            String deviceProduct = info.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
            if ((product != null) && product.equals(deviceProduct)) {
                return info;
            }
        }
    }
    return null;
}
 
源代码14 项目: android-midisuite   文件: MidiPrinter.java
public static String formatDeviceInfo(MidiDeviceInfo info) {
    StringBuilder sb = new StringBuilder();
    if (info != null) {
        Bundle properties = info.getProperties();
        for (String key : properties.keySet()) {
            Object value = properties.get(key);
            sb.append(key).append(" = ").append(value).append('\n');
        }
        for (PortInfo port : info.getPorts()) {
            sb.append((port.getType() == PortInfo.TYPE_INPUT) ? "input"
                    : "output");
            sb.append("[").append(port.getPortNumber()).append("] = \"").append(port.getName()
                    + "\"\n");
        }
    }
    return sb.toString();
}
 
源代码15 项目: android-midisuite   文件: MidiInputPortSelector.java
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    close();
    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mInputPort = mOpenDevice.openInputPort(
                            wrapper.getPortIndex());
                    if (mInputPort == null) {
                        Log.e(MidiConstants.TAG, "could not open input port on " + info);
                    }
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openInputPort might take a while.
    }
}
 
源代码16 项目: android-MidiScope   文件: MidiPrinter.java
public static String formatDeviceInfo(MidiDeviceInfo info) {
    StringBuilder sb = new StringBuilder();
    if (info != null) {
        Bundle properties = info.getProperties();
        for (String key : properties.keySet()) {
            Object value = properties.get(key);
            sb.append(key).append(" = ").append(value).append('\n');
        }
        for (PortInfo port : info.getPorts()) {
            sb.append((port.getType() == PortInfo.TYPE_INPUT) ? "input" : "output")
                    .append("[")
                    .append(port.getPortNumber())
                    .append("] = \"")
                    .append(port.getName()).append("\"\n");
        }
    }
    return sb.toString();
}
 
源代码17 项目: android-MidiScope   文件: MidiInputPortSelector.java
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    close();
    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mInputPort = mOpenDevice.openInputPort(
                            wrapper.getPortIndex());
                    if (mInputPort == null) {
                        Log.e(MidiConstants.TAG, "could not open input port on " + info);
                    }
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openInputPort might take a while.
    }
}
 
源代码18 项目: android-MidiScope   文件: MidiTools.java
/**
 * @return a device that matches the manufacturer and product or null
 */
public static MidiDeviceInfo findDevice(MidiManager midiManager,
        String manufacturer, String product) {
    for (MidiDeviceInfo info : midiManager.getDevices()) {
        String deviceManufacturer = info.getProperties()
                .getString(MidiDeviceInfo.PROPERTY_MANUFACTURER);
        if ((manufacturer != null)
                && manufacturer.equals(deviceManufacturer)) {
            String deviceProduct = info.getProperties()
                    .getString(MidiDeviceInfo.PROPERTY_PRODUCT);
            if ((product != null) && product.equals(deviceProduct)) {
                return info;
            }
        }
    }
    return null;
}
 
源代码19 项目: android-midisuite   文件: MidiDeviceMonitor.java
@Override
public void onDeviceRemoved(final MidiDeviceInfo device) {
    for(Map.Entry<DeviceCallback, Handler> item : mCallbacks.entrySet()) {
        final DeviceCallback callback = item.getKey();
        Handler handler = item.getValue();
        if(handler == null) {
            callback.onDeviceRemoved(device);
        } else {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    callback.onDeviceRemoved(device);
                }
            });
        }
    }
}
 
源代码20 项目: media-samples   文件: MidiOutputPortSelector.java
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    Log.i(MidiConstants.TAG, "onPortSelected: " + wrapper);
    close();

    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {

                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mOutputPort = device.openOutputPort(wrapper.getPortIndex());
                    if (mOutputPort == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open output port for " + info);
                        return;
                    }
                    mOutputPort.connect(mDispatcher);
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openOutputPort might take a while.
    }
}
 
源代码21 项目: media-samples   文件: MidiPortSelector.java
@Override
public void onDeviceAdded(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        mAdapter.add(wrapper);
        Log.i(MidiConstants.TAG, wrapper + " was added");
        mAdapter.notifyDataSetChanged();
    }
}
 
源代码22 项目: media-samples   文件: MidiPortSelector.java
@Override
public void onDeviceRemoved(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        MidiPortWrapper currentWrapper = mCurrentWrapper;
        mAdapter.remove(wrapper);
        // If the currently selected port was removed then select no port.
        if (wrapper.equals(currentWrapper)) {
            clearSelection();
        }
        mAdapter.notifyDataSetChanged();
        Log.i(MidiConstants.TAG, wrapper + " was removed");
    }
}
 
源代码23 项目: media-samples   文件: MidiPortSelector.java
@Override
public void onDeviceStatusChanged(final MidiDeviceStatus status) {
    // If an input port becomes busy then remove it from the menu.
    // If it becomes free then add it back to the menu.
    if (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT) {
        MidiDeviceInfo info = status.getDeviceInfo();
        Log.i(MidiConstants.TAG, "MidiPortSelector.onDeviceStatusChanged status = " + status
                + ", mType = " + mType
                + ", activity = " + mActivity.getPackageName()
                + ", info = " + info);
        // Look for transitions from free to busy.
        int portCount = info.getInputPortCount();
        for (int i = 0; i < portCount; ++i) {
            MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
            if (!wrapper.equals(mCurrentWrapper)) {
                if (status.isInputPortOpen(i)) { // busy?
                    if (!mBusyPorts.contains(wrapper)) {
                        // was free, now busy
                        mBusyPorts.add(wrapper);
                        mAdapter.remove(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                } else {
                    if (mBusyPorts.remove(wrapper)) {
                        // was busy, now free
                        mAdapter.add(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                }
            }
        }
    }
}
 
/**
 * @param midiManager
 * @param activity
 * @param spinnerId
 * @param type
 */
public MidiOutputPortConnectionSelector(MidiManager midiManager,
        Activity activity, int spinnerId,
        MidiDeviceInfo destinationDeviceInfo, int destinationPortIndex) {
    super(midiManager, activity, spinnerId,
            MidiDeviceInfo.PortInfo.TYPE_OUTPUT);
    mDestinationDeviceInfo = destinationDeviceInfo;
    mDestinationPortIndex = destinationPortIndex;
}
 
源代码25 项目: media-samples   文件: MidiPortConnector.java
/**
 * Open a source device and connect its output port to the
 * destinationInputPort.
 *
 * @param sourceDeviceInfo
 * @param sourcePortIndex
 * @param destinationInputPort
 */
private void connectToDevicePort(final MidiDeviceInfo sourceDeviceInfo,
        final int sourcePortIndex,
        final MidiInputPort destinationInputPort,
        final OnPortsConnectedListener listener, final Handler handler) {
    mMidiManager.openDevice(sourceDeviceInfo,
            new MidiManager.OnDeviceOpenedListener() {
                @Override
                public void onDeviceOpened(MidiDevice device) {
                    if (device == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open " + sourceDeviceInfo);
                        safeClose();
                        if (listener != null) {
                            listener.onPortsConnected(null);
                        }
                    } else {
                        Log.i(MidiConstants.TAG,
                                "connectToDevicePort opened "
                                        + sourceDeviceInfo);
                        // Device was opened so connect the ports.
                        mSourceDevice = device;
                        mConnection = device.connectPorts(
                                destinationInputPort, sourcePortIndex);
                        if (mConnection == null) {
                            Log.e(MidiConstants.TAG, "could not connect to "
                                    + sourceDeviceInfo);
                            safeClose();
                        }
                        if (listener != null) {
                            listener.onPortsConnected(mConnection);
                        }
                    }
                }
            }, handler);
}
 
源代码26 项目: media-samples   文件: MainActivity.java
private void setupMidi() {
    // Setup MIDI
    MidiManager midiManager = (MidiManager) getSystemService(MIDI_SERVICE);

    MidiDeviceInfo synthInfo = MidiTools.findDevice(midiManager, "AndroidTest",
            "SynthExample");
    int portIndex = 0;
    mPortSelector = new MidiOutputPortConnectionSelector(midiManager, this,
            R.id.spinner_synth_sender, synthInfo, portIndex);
    mPortSelector.setConnectedListener(new MyPortsConnectedListener());
}
 
源代码27 项目: media-samples   文件: MidiOutputPortSelector.java
@Override
public void onPortSelected(final MidiPortWrapper wrapper) {
    Log.i(MidiConstants.TAG, "onPortSelected: " + wrapper);
    close();

    final MidiDeviceInfo info = wrapper.getDeviceInfo();
    if (info != null) {
        mMidiManager.openDevice(info, new MidiManager.OnDeviceOpenedListener() {

                @Override
            public void onDeviceOpened(MidiDevice device) {
                if (device == null) {
                    Log.e(MidiConstants.TAG, "could not open " + info);
                } else {
                    mOpenDevice = device;
                    mOutputPort = device.openOutputPort(wrapper.getPortIndex());
                    if (mOutputPort == null) {
                        Log.e(MidiConstants.TAG,
                                "could not open output port for " + info);
                        return;
                    }
                    mOutputPort.connect(mDispatcher);
                }
            }
        }, null);
        // Don't run the callback on the UI thread because openOutputPort might take a while.
    }
}
 
源代码28 项目: media-samples   文件: MidiPortSelector.java
@Override
public void onDeviceAdded(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        mAdapter.add(wrapper);
        Log.i(MidiConstants.TAG, wrapper + " was added");
        mAdapter.notifyDataSetChanged();
    }
}
 
源代码29 项目: media-samples   文件: MidiPortSelector.java
@Override
public void onDeviceRemoved(final MidiDeviceInfo info) {
    int portCount = getInfoPortCount(info);
    for (int i = 0; i < portCount; ++i) {
        MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
        MidiPortWrapper currentWrapper = mCurrentWrapper;
        mAdapter.remove(wrapper);
        // If the currently selected port was removed then select no port.
        if (wrapper.equals(currentWrapper)) {
            clearSelection();
        }
        mAdapter.notifyDataSetChanged();
        Log.i(MidiConstants.TAG, wrapper + " was removed");
    }
}
 
源代码30 项目: media-samples   文件: MidiPortSelector.java
@Override
public void onDeviceStatusChanged(final MidiDeviceStatus status) {
    // If an input port becomes busy then remove it from the menu.
    // If it becomes free then add it back to the menu.
    if (mType == MidiDeviceInfo.PortInfo.TYPE_INPUT) {
        MidiDeviceInfo info = status.getDeviceInfo();
        Log.i(MidiConstants.TAG, "MidiPortSelector.onDeviceStatusChanged status = " + status
                + ", mType = " + mType
                + ", activity = " + mActivity.getPackageName()
                + ", info = " + info);
        // Look for transitions from free to busy.
        int portCount = info.getInputPortCount();
        for (int i = 0; i < portCount; ++i) {
            MidiPortWrapper wrapper = new MidiPortWrapper(info, mType, i);
            if (!wrapper.equals(mCurrentWrapper)) {
                if (status.isInputPortOpen(i)) { // busy?
                    if (!mBusyPorts.contains(wrapper)) {
                        // was free, now busy
                        mBusyPorts.add(wrapper);
                        mAdapter.remove(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                } else {
                    if (mBusyPorts.remove(wrapper)) {
                        // was busy, now free
                        mAdapter.add(wrapper);
                        mAdapter.notifyDataSetChanged();
                    }
                }
            }
        }
    }
}
 
 类所在包
 同包方法