From c4528995435f4b82ec104329002c1c25308a6425 Mon Sep 17 00:00:00 2001 From: Likai Ding Date: Wed, 18 May 2016 13:59:06 +0800 Subject: Gallery: MediaPlayer/Metadata wrapper CRs-Fixed: 986672 Change-Id: Ia290c2043d0d6a01df0ff2a07d143e15078ca109 --- .../com/android/gallery3d/common/ApiHelper.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'gallerycommon') diff --git a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java index 1c3ffcd67..434771b6e 100644 --- a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java +++ b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java @@ -301,4 +301,55 @@ public class ApiHelper { invoke(setMethod, null, key, val); } } + + public static class Metadata { + public static final int PAUSE_AVAILABLE = 1; + public static final int SEEK_BACKWARD_AVAILABLE = 2; + public static final int SEEK_FORWARD_AVAILABLE = 3; + public static final int SEEK_AVAILABLE = 4; + + private static final Method hasMethod; + private static final Method getIntMethod; + private static final Method getBooleanMethod; + + static { + Class klass = getClassForName("android.media.Metadata"); + hasMethod = getMethod(klass, "has", int.class); + getIntMethod = getMethod(klass, "getInt", int.class); + getBooleanMethod = getMethod(klass, "getBoolean", int.class); + } + + private Object mMetadata; + + Metadata(Object obj) { + mMetadata = obj; + } + + public boolean has(final int metadataId) { + Object obj = invoke(hasMethod, mMetadata, metadataId); + return obj == null ? false : (Boolean) obj; + } + + public int getInt(final int key) { + Object obj = invoke(getIntMethod, mMetadata, key); + return obj == null ? 0 : (Integer) obj; + } + + public boolean getBoolean(final int key) { + Object obj = invoke(getBooleanMethod, mMetadata, key); + return obj == null ? false : (Boolean) obj; + } + } + + public static class MediaPlayer { + public static final boolean METADATA_ALL = false; + public static final boolean BYPASS_METADATA_FILTER = false; + + public static Metadata getMetadata(android.media.MediaPlayer mp, + final boolean update_only, final boolean apply_filter) { + Method method = getMethod(mp.getClass(), "getMetadata", boolean.class, boolean.class); + Object obj = invoke(method, mp, update_only, apply_filter); + return obj == null ? null : new Metadata(obj); + } + } } -- cgit v1.2.3