diff --git a/media/java/android/media/midi/package.html b/media/java/android/media/midi/package.html index 8b2bd1666a068..673c4ba9bfeba 100644 --- a/media/java/android/media/midi/package.html +++ b/media/java/android/media/midi/package.html @@ -10,27 +10,28 @@

The Android MIDI package allows users to:

The API features include:

-

Transports Supported

@@ -65,6 +66,14 @@ the MidiService.

Writing a MIDI Application

+

Declare Feature in Manifest

+ +

An app that requires the MIDI API should declare that in the AndroidManifest.xml file. +Then the app will not appear in the Play Store for old devices that do not support the MIDI API.

+ +
+<uses-feature android:name="android.software.midi" android:required="true"/>
+

The MidiManager

@@ -132,11 +141,15 @@ String manufacturer = properties

Other properties include PROPERTY_PRODUCT, PROPERTY_NAME, PROPERTY_SERIAL_NUMBER

-

You can get the names of the ports from a PortInfo object.

+

You can get the names and types of the ports from a PortInfo object. +The type will be either TYPE_INPUT or TYPE_OUTPUT.

-PortInfo portInfo = info.getInputPortInfo(i);
-String portName = portInfo.getName();
+MidiDeviceInfo.PortInfo[] portInfos = info.getPorts();
+String portName = portInfos[0].getName();
+if (portInfos[0].getType() == MidiDeviceInfo.PortInfo.TYPE_INPUT) {
+    ...
+}
 
@@ -196,8 +209,9 @@ consistent with the other audio and input timers.

Here we send a message with a timestamp 2 seconds in the future.

+final long NANOS_PER_SECOND = 1000000000L;
 long now = System.nanoTime();
-long future = now + (2 * 1000000000);
+long future = now + (2 * NANOS_PER_SECOND);
 inputPort.send(buffer, offset, numBytes, future);
 
@@ -263,7 +277,8 @@ AndroidManifest.xml file.

The details of the resource in this example is stored in -“res/xml/synth_device_info.xml”.

+“res/xml/synth_device_info.xml”. The port names that you +declare in this file will be available from PortInfo.getName().

 <devices>
@@ -288,6 +303,8 @@ import android.media.midi.MidiReceiver;
 public class MidiSynthDeviceService extends MidiDeviceService {
     private static final String TAG = "MidiSynthDeviceService";
     private MySynthEngine mSynthEngine = new MySynthEngine();
+    private boolean synthStarted = false;
+
     @Override
     public void onCreate() {
         super.onCreate();
@@ -311,10 +328,12 @@ public class MidiSynthDeviceService extends MidiDeviceService {
      */
     @Override
     public void onDeviceStatusChanged(MidiDeviceStatus status) {
-        if (status.isInputPortOpen(0)) {
+        if (status.isInputPortOpen(0) && !synthStarted) {
             mSynthEngine.start();
-        } else {
+            synthStarted = true;
+        } else if (!status.isInputPortOpen(0) && synthStarted){
             mSynthEngine.stop();
+            synthStarted = false;
         }
     }
 }