summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLikai Ding <likaid@codeaurora.org>2016-05-18 13:59:06 +0800
committerLikai Ding <likaid@codeaurora.org>2016-06-03 15:34:47 +0800
commitc4528995435f4b82ec104329002c1c25308a6425 (patch)
tree826cf9eea5c15eca642de02070e27c52e37f6a9e
parent711aee7790ab995e61231e836bfe36a38f65cfce (diff)
downloadandroid_packages_apps_Gallery2-c4528995435f4b82ec104329002c1c25308a6425.tar.gz
android_packages_apps_Gallery2-c4528995435f4b82ec104329002c1c25308a6425.tar.bz2
android_packages_apps_Gallery2-c4528995435f4b82ec104329002c1c25308a6425.zip
Gallery: MediaPlayer/Metadata wrapper
CRs-Fixed: 986672 Change-Id: Ia290c2043d0d6a01df0ff2a07d143e15078ca109
-rw-r--r--gallerycommon/src/com/android/gallery3d/common/ApiHelper.java51
-rw-r--r--src/com/android/gallery3d/app/MoviePlayer.java9
-rw-r--r--src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java10
3 files changed, 61 insertions, 9 deletions
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);
+ }
+ }
}
diff --git a/src/com/android/gallery3d/app/MoviePlayer.java b/src/com/android/gallery3d/app/MoviePlayer.java
index a16cc9a33..520b462ee 100644
--- a/src/com/android/gallery3d/app/MoviePlayer.java
+++ b/src/com/android/gallery3d/app/MoviePlayer.java
@@ -31,7 +31,6 @@ import android.content.SharedPreferences;
import android.graphics.Color;
import android.media.AudioManager;
import android.media.MediaPlayer;
-import android.media.Metadata;
import android.media.audiofx.Virtualizer;
import android.net.Uri;
import android.os.Build;
@@ -987,10 +986,10 @@ public class MoviePlayer implements
private void getVideoInfo(MediaPlayer mp) {
if (!MovieUtils.isLocalFile(mMovieItem.getUri(), mMovieItem.getMimeType())) {
- Metadata data = mp.getMetadata(MediaPlayer.METADATA_ALL,
- MediaPlayer.BYPASS_METADATA_FILTER);
+ ApiHelper.Metadata data = ApiHelper.MediaPlayer.getMetadata(mp,
+ ApiHelper.MediaPlayer.METADATA_ALL,
+ ApiHelper.MediaPlayer.BYPASS_METADATA_FILTER);
if (data != null) {
- // TODO comments by sunlei
mServerTimeoutExt.setVideoInfo(data);
} else {
Log.w(TAG, "Metadata is null!");
@@ -1438,7 +1437,7 @@ public class MoviePlayer implements
return false;
}
- public void setVideoInfo(Metadata data) {
+ public void setVideoInfo(ApiHelper.Metadata data) {
mServerTimeout = RESUME_DIALOG_TIMEOUT;
if (data.has(SERVER_TIMEOUT)) {
mServerTimeout = data.getInt(SERVER_TIMEOUT);
diff --git a/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java b/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java
index d787d8daf..ace5cec64 100644
--- a/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java
+++ b/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java
@@ -4,13 +4,11 @@ import android.app.AlertDialog;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.Intent;
import android.content.res.Resources;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
-import android.media.Metadata;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnInfoListener;
@@ -29,6 +27,9 @@ import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.MediaController;
import android.widget.MediaController.MediaPlayerControl;
+import com.android.gallery3d.common.ApiHelper;
+import com.android.gallery3d.common.ApiHelper.Metadata;
+
import org.codeaurora.gallery3d.video.ScreenModeManager.ScreenModeListener;
import java.io.IOException;
@@ -225,8 +226,9 @@ public class CodeauroraVideoView extends SurfaceView implements MediaPlayerContr
}
//Here we can get meta data from mediaplayer.
// Get the capabilities of the player for this stream
- final Metadata data = mp.getMetadata(MediaPlayer.METADATA_ALL,
- MediaPlayer.BYPASS_METADATA_FILTER);
+ final Metadata data = ApiHelper.MediaPlayer.getMetadata(mp,
+ ApiHelper.MediaPlayer.METADATA_ALL,
+ ApiHelper.MediaPlayer.BYPASS_METADATA_FILTER);
if (data != null) {
mCanPause = !data.has(Metadata.PAUSE_AVAILABLE)
|| data.getBoolean(Metadata.PAUSE_AVAILABLE);