下面列出了怎么用android.media.midi.MidiDeviceStatus的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void onDeviceStatusChanged(final MidiDeviceStatus status) {
for(Map.Entry<DeviceCallback, Handler> item : mCallbacks.entrySet()) {
final DeviceCallback callback = item.getKey();
Handler handler = item.getValue();
if(handler == null) {
callback.onDeviceStatusChanged(status);
} else {
handler.post(new Runnable() {
@Override
public void run() {
callback.onDeviceStatusChanged(status);
}
});
}
}
}
/**
* This will get called when clients connect or disconnect.
* Log device information.
*/
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
if (mScopeLogger != null) {
if (status.isInputPortOpen(0)) {
mScopeLogger.log("=== connected ===");
String text = MidiPrinter.formatDeviceInfo(
status.getDeviceInfo());
mScopeLogger.log(text);
} else {
mScopeLogger.log("--- disconnected ---");
}
}
}
@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();
}
}
}
}
}
}
/**
* This will get called when clients connect or disconnect.
*/
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
if (status.isInputPortOpen(0) && !mSynthStarted) {
mSynthEngine.start();
mSynthStarted = true;
} else if (!status.isInputPortOpen(0) && mSynthStarted) {
mSynthEngine.stop();
mSynthStarted = false;
}
}
@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();
}
}
}
}
}
}
/**
* This will get called when clients connect or disconnect.
*/
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
if (status.isInputPortOpen(0) && !mSynthStarted) {
mSynthEngine.start();
mSynthStarted = true;
} else if (!status.isInputPortOpen(0) && mSynthStarted) {
mSynthEngine.stop();
mSynthStarted = false;
}
}
@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();
}
}
}
}
}
}
/**
* This will get called when clients connect or disconnect.
* Log device information.
*/
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
if (mScopeLogger != null) {
if (status.isInputPortOpen(0)) {
mScopeLogger.log("=== connected ===");
String text = MidiPrinter.formatDeviceInfo(
status.getDeviceInfo());
mScopeLogger.log(text);
} else {
mScopeLogger.log("--- disconnected ---");
}
}
}
@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();
}
}
}
}
}
}
/**
* This will get called when clients connect or disconnect.
* Log device information.
*/
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
if (mScopeLogger != null) {
if (status.isInputPortOpen(0)) {
mScopeLogger.log("=== connected ===");
String text = MidiPrinter.formatDeviceInfo(
status.getDeviceInfo());
mScopeLogger.log(text);
} else {
mScopeLogger.log("--- disconnected ---");
}
}
}
/**
* This will get called when clients connect or disconnect.
*/
@Override
public void onDeviceStatusChanged(MidiDeviceStatus status) {
if (status.isInputPortOpen(0) && !mSynthStarted) {
mSynthEngine.start();
mSynthStarted = true;
} else if (!status.isInputPortOpen(0) && mSynthStarted){
mSynthEngine.stop();
mSynthStarted = false;
}
}
@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();
}
}
}
}
}
}