OSDN Git Service

MediaFormat: add getInteger with default value convenience method
authorLajos Molnar <lajos@google.com>
Thu, 12 Sep 2013 04:04:49 +0000 (21:04 -0700)
committerLajos Molnar <lajos@google.com>
Thu, 12 Sep 2013 22:35:31 +0000 (15:35 -0700)
Change-Id: I58947a2f4a286fef74f74cb189469278056d4759
Signed-off-by: Lajos Molnar <lajos@google.com>
Bug: 10326117

media/java/android/media/MediaFormat.java

index fd4c81b..16ae43d 100644 (file)
@@ -273,6 +273,20 @@ public final class MediaFormat {
     }
 
     /**
+     * Returns the value of an integer key, or the default value if the
+     * key is missing or is for another type value.
+     * @hide
+     */
+    public final int getInteger(String name, int defaultValue) {
+        try {
+            return getInteger(name);
+        }
+        catch (NullPointerException  e) { /* no such field */ }
+        catch (ClassCastException e) { /* field of different type */ }
+        return defaultValue;
+    }
+
+    /**
      * Returns the value of a long key.
      */
     public final long getLong(String name) {