九游游戏中心HD v4.6.8.1版本的 MD5 值为:78c397802cc5ffdcc7f5502ede90502e
以下内容为反编译后的 MediaMetadataUtil.java 源代码,内容仅作参考
package com.uc.media.interfaces.util;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
import com.uc.media.interfaces.PlayerType;
import com.uc.webview.export.annotations.Reflection;
import com.uc.webview.export.internal.setup.UCSetupTask;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@Reflection
public class MediaMetadataUtil {
private static final String LOGTAG = "MediaMetadataUtil";
public static class MetadataCache {
public static String mBitrate;
public static String mDataSource;
public static String mDuration;
private MetadataCache() {
}
}
@Reflection
public static class MediaPlayerMetadataRetriever {
public static final String ApolloMediaMetadataRetrieverPackName = "com.UCMobile.Apollo.ThumbnailUtils";
private static final String METADATA_KEY_BITRATE = "METADATA_KEY_BITRATE";
private static final String METADATA_KEY_DURATION = "METADATA_KEY_DURATION";
public static final String VitamioMediaMetadataRetrieverPackName = "io.vov.vitamio.MediaMetadataRetriever";
private static Object mVideoCaptureObject = null;
public static final String SystemMediaMetadataRetrieverPackName = "android.media.MediaMetadataRetriever";
private static String MediaMetadataRetrieverPackName = SystemMediaMetadataRetrieverPackName;
private MediaPlayerMetadataRetriever() {
}
public static void setMediaMetadataRetrieverPackName(String str) {
if (str != null) {
MediaMetadataRetrieverPackName = str;
}
}
public static PlayerType getRecommandPlayerType(Context context) {
PlayerType playerType;
Exception e;
PlayerType playerType2 = PlayerType.UNKNOWN;
try {
playerType = (PlayerType) UCSetupTask.classForName("com.uc.media.VideoViewFactory").getDeclaredMethod("getRecommandPlayerType", Context.class).invoke(null, context);
try {
new StringBuilder("get Recommand PlayerType: ").append(playerType);
} catch (Exception e2) {
e = e2;
Log.e(MediaMetadataUtil.LOGTAG, "get Recommand PlayerType error: " + e);
return playerType;
}
} catch (Exception e3) {
playerType = playerType2;
e = e3;
}
return playerType;
}
public static Object createMediaMetadataRetriever(String str) {
boolean videoURI;
if (!MediaMetadataRetrieverPackName.equals(SystemMediaMetadataRetrieverPackName)) {
new StringBuilder("create system player MediaMetadataRetriever error: illegal package name ").append(MediaMetadataRetrieverPackName);
return null;
}
if (Build.VERSION.SDK_INT > 9) {
try {
new StringBuilder("Build.VERSION.SDK_INT = ").append(Build.VERSION.SDK_INT).append(" create MediaMetadataRetriever by reflection.");
Object newInstance = Class.forName(MediaMetadataRetrieverPackName).getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
mVideoCaptureObject = newInstance;
if (newInstance != null && str != null) {
if (isLoacalFile(str)) {
videoURI = setVideoURI(str);
} else {
videoURI = setVideoURI(str, new HashMap());
}
if (!videoURI) {
Log.e(MediaMetadataUtil.LOGTAG, "create MediaPlayerMetadataRetriever success : " + mVideoCaptureObject + ", but initialize failed.");
release();
}
}
} catch (NoSuchMethodException e) {
} catch (Exception e2) {
}
} else {
mVideoCaptureObject = null;
}
return mVideoCaptureObject;
}
public static Object createMediaMetadataRetriever(Context context, String str) {
if (context == null || MediaMetadataRetrieverPackName.equals(SystemMediaMetadataRetrieverPackName)) {
new StringBuilder("create MediaMetadataRetriever error: context is null or illegal package name ").append(MediaMetadataRetrieverPackName);
return null;
}
try {
Object newInstance = Class.forName(MediaMetadataRetrieverPackName).getDeclaredConstructor(Context.class).newInstance(context);
mVideoCaptureObject = newInstance;
if (newInstance != null && str != null && !setVideoURI(str)) {
Log.e(MediaMetadataUtil.LOGTAG, "create VitamioPlayerMetadataRetriever success : " + mVideoCaptureObject + ", but initialize failed.");
release();
}
} catch (NoSuchMethodException e) {
} catch (Exception e2) {
}
return mVideoCaptureObject;
}
public static Bitmap getEmbeddedPicture() {
Method declaredMethod;
Bitmap frameAtTime;
if (!MediaMetadataRetrieverPackName.equals(SystemMediaMetadataRetrieverPackName)) {
new StringBuilder("getEmbeddedPicture error: illegal package name ").append(MediaMetadataRetrieverPackName);
return null;
}
if (mVideoCaptureObject != null) {
try {
declaredMethod = Class.forName(MediaMetadataRetrieverPackName).getDeclaredMethod("getEmbeddedPicture", new Class[0]);
} catch (NoSuchMethodException e) {
} catch (Exception e2) {
}
if (declaredMethod != null) {
byte[] bArr = (byte[]) declaredMethod.invoke(mVideoCaptureObject, null);
if (bArr != null) {
frameAtTime = BitmapFactory.decodeByteArray(bArr, 0, bArr.length);
} else {
Log.e(MediaMetadataUtil.LOGTAG, "getEmbeddedPicture failed ,try getFrameAtTime ");
frameAtTime = getFrameAtTime();
}
return frameAtTime;
}
}
frameAtTime = null;
return frameAtTime;
}
public static Map<String, String> getMetadata() {
HashMap hashMap = new HashMap();
String[] strArr = {METADATA_KEY_BITRATE, METADATA_KEY_DURATION};
if (!MediaMetadataRetrieverPackName.equals(SystemMediaMetadataRetrieverPackName)) {
new StringBuilder("getMetadata error: illegal package name ").append(MediaMetadataRetrieverPackName);
return null;
}
if (mVideoCaptureObject != null) {
try {
Class<?> cls = Class.forName(MediaMetadataRetrieverPackName);
Method declaredMethod = cls.getDeclaredMethod("extractMetadata", Integer.TYPE);
if (declaredMethod != null) {
for (int i = 0; i < 2; i++) {
String str = (String) declaredMethod.invoke(mVideoCaptureObject, Integer.valueOf(cls.getDeclaredField(strArr[i]).getInt(mVideoCaptureObject)));
if (str != null) {
hashMap.put(strArr[i], str);
new StringBuilder("getMetadata \"").append(strArr[i]).append("\": ").append(str);
} else {
Log.e(MediaMetadataUtil.LOGTAG, "getMetadata \"" + strArr[i] + "\" failed.");
}
}
return hashMap;
}
} catch (NoSuchMethodException e) {
} catch (Exception e2) {
}
}
return null;
}
private static Bitmap getFrameAtTime() {
if (!MediaMetadataRetrieverPackName.equals(SystemMediaMetadataRetrieverPackName)) {
new StringBuilder("getFrameAtTime error: illegal package name ").append(MediaMetadataRetrieverPackName);
return null;
}
if (mVideoCaptureObject != null) {
try {
Method declaredMethod = Class.forName(MediaMetadataRetrieverPackName).getDeclaredMethod("getFrameAtTime", new Class[0]);
if (declaredMethod != null) {
return (Bitmap) declaredMethod.invoke(mVideoCaptureObject, null);
}
} catch (NoSuchMethodException e) {
} catch (Exception e2) {
}
}
return null;
}
public static Bitmap getFrameAtTime(long j) {
if (mVideoCaptureObject != null) {
if (MediaMetadataRetrieverPackName.equals(SystemMediaMetadataRetrieverPackName)) {
try {
Class<?> cls = Class.forName(MediaMetadataRetrieverPackName);
Method declaredMethod = cls.getDeclaredMethod("getFrameAtTime", Long.TYPE, Integer.TYPE);
if (declaredMethod != null) {
return (Bitmap) declaredMethod.invoke(mVideoCaptureObject, Long.valueOf(j), Integer.valueOf(cls.getDeclaredField("OPTION_PREVIOUS_SYNC").getInt(mVideoCaptureObject)));
}
} catch (NoSuchMethodException e) {
} catch (Exception e2) {
}
} else {
try {
Method declaredMethod2 = Class.forName(MediaMetadataRetrieverPackName).getDeclaredMethod("getFrameAtTime", Long.TYPE);
if (declaredMethod2 != null) {
return (Bitmap) declaredMethod2.invoke(mVideoCaptureObject, Long.valueOf(j));
}
} catch (NoSuchMethodException e3) {
} catch (Exception e4) {
}
}
}
return null;
}
public static void release() {
if (mVideoCaptureObject != null) {
try {
Method declaredMethod = Class.forName(MediaMetadataRetrieverPackName).getDeclaredMethod("release", new Class[0]);
if (declaredMethod != null) {
declaredMethod.invoke(mVideoCaptureObject, null);
}
} catch (NoSuchMethodException e) {
} catch (Exception e2) {
}
mVideoCaptureObject = null;
}
}
private static boolean setVideoURI(String str) {
if (mVideoCaptureObject != null) {
try {
if (str.indexOf("file:///") != -1) {
str = str.replace("file:///", "file://");
}
Method declaredMethod = Class.forName(MediaMetadataRetrieverPackName).getDeclaredMethod("setDataSource", FileDescriptor.class);
if (declaredMethod != null) {
FileInputStream fileInputStream = new FileInputStream(new File(str));
declaredMethod.invoke(mVideoCaptureObject, fileInputStream.getFD());
fileInputStream.close();
return true;
}
Log.e(MediaMetadataUtil.LOGTAG, "set datasource for MediaMetadataRetriever error : getDeclaredMethod failed.");
} catch (NoSuchMethodException e) {
} catch (Exception e2) {
}
}
return false;
}
private static boolean setVideoURI(String str, Map<String, String> map) {
if (mVideoCaptureObject != null) {
try {
Method declaredMethod = Class.forName(MediaMetadataRetrieverPackName).getDeclaredMethod("setDataSource", String.class, Map.class);
if (declaredMethod != null) {
declaredMethod.invoke(mVideoCaptureObject, str, map);
return true;
}
Log.e(MediaMetadataUtil.LOGTAG, "set datasource for MediaMetadataRetriever error : getDeclaredMethod failed.");
} catch (NoSuchMethodException e) {
} catch (Exception e2) {
}
}
return false;
}
private static boolean isLoacalFile(String str) {
if (str.indexOf("http://") != -1) {
return false;
}
if (str.indexOf("file:///") != -1) {
str = str.replace("file:///", "file://");
}
new StringBuilder().append(str).append(" is local file.");
return true;
}
}
private static boolean getVideoThumbnailBySystemPlayer(String str, Rect rect, Bitmap bitmap) {
boolean z;
if (bitmap == null || rect == null || rect.width() == 0 || rect.height() == 0) {
Log.e(LOGTAG, "Bitmap object is null or target Rect is 0.");
return false;
}
MediaPlayerMetadataRetriever.setMediaMetadataRetrieverPackName(MediaPlayerMetadataRetriever.SystemMediaMetadataRetrieverPackName);
if (MediaPlayerMetadataRetriever.createMediaMetadataRetriever(str) != null) {
Bitmap embeddedPicture = MediaPlayerMetadataRetriever.getEmbeddedPicture();
if (embeddedPicture != null) {
Rect rect2 = new Rect(0, 0, embeddedPicture.getWidth(), embeddedPicture.getHeight());
new StringBuilder("video frame source : ").append(embeddedPicture.getWidth()).append(" X ").append(embeddedPicture.getHeight());
new Canvas(bitmap).drawBitmap(embeddedPicture, rect2, rect, (Paint) null);
z = true;
} else {
z = false;
}
Map<String, String> metadata = MediaPlayerMetadataRetriever.getMetadata();
if (metadata != null) {
MetadataCache.mDataSource = str;
MetadataCache.mBitrate = metadata.get("METADATA_KEY_BITRATE");
MetadataCache.mDuration = metadata.get("METADATA_KEY_DURATION");
}
MediaPlayerMetadataRetriever.release();
return z;
}
return false;
}
public static synchronized boolean getVideoThumbnail(Context context, String str, Rect rect, Bitmap bitmap) {
boolean z;
boolean z2 = false;
synchronized (MediaMetadataUtil.class) {
if (bitmap != null && rect != null) {
if (rect.width() != 0 && rect.height() != 0) {
PlayerType recommandPlayerType = MediaPlayerMetadataRetriever.getRecommandPlayerType(context);
if (PlayerType.UNKNOWN == recommandPlayerType || PlayerType.SYSTEM == recommandPlayerType) {
z2 = getVideoThumbnailBySystemPlayer(str, rect, bitmap);
} else {
if (PlayerType.VITAMIO == recommandPlayerType) {
MediaPlayerMetadataRetriever.setMediaMetadataRetrieverPackName(MediaPlayerMetadataRetriever.VitamioMediaMetadataRetrieverPackName);
if (MediaPlayerMetadataRetriever.createMediaMetadataRetriever(context, str) != null) {
Bitmap frameAtTime = MediaPlayerMetadataRetriever.getFrameAtTime(-1L);
if (frameAtTime != null) {
Rect rect2 = new Rect(0, 0, frameAtTime.getWidth(), frameAtTime.getHeight());
new StringBuilder("video frame source : ").append(frameAtTime.getWidth()).append(" X ").append(frameAtTime.getHeight());
new Canvas(bitmap).drawBitmap(frameAtTime, rect2, rect, (Paint) null);
z = true;
} else {
z = false;
}
MediaPlayerMetadataRetriever.release();
} else {
z = false;
}
z2 = z;
} else if (PlayerType.APOLLO == recommandPlayerType) {
try {
Bitmap bitmap2 = (Bitmap) Class.forName(MediaPlayerMetadataRetriever.ApolloMediaMetadataRetrieverPackName).getDeclaredMethod("createVideoThumbnail", Context.class, String.class, Integer.TYPE).invoke(null, context, str, -1);
if (bitmap2 != null) {
Rect rect3 = new Rect(0, 0, bitmap2.getWidth(), bitmap2.getHeight());
new StringBuilder("video frame source : ").append(bitmap2.getWidth()).append(" X ").append(bitmap2.getHeight());
new Canvas(bitmap).drawBitmap(bitmap2, rect3, rect, (Paint) null);
z2 = true;
}
} catch (Exception e) {
new StringBuilder("createVideoThumbnail error : ").append(e);
}
}
if (!z2) {
z2 = getVideoThumbnailBySystemPlayer(str, rect, bitmap);
}
}
}
}
Log.e(LOGTAG, "Bitmap object is null or target Rect is 0.");
}
return z2;
}
public static synchronized String getAverageBitrate(String str) {
String str2;
synchronized (MediaMetadataUtil.class) {
if (MetadataCache.mDataSource != null && MetadataCache.mDataSource.equals(str) && MetadataCache.mBitrate != null) {
new StringBuilder("get average bitrate from cache: ").append(MetadataCache.mBitrate);
str2 = MetadataCache.mBitrate;
} else {
Map<String, String> metaData = getMetaData(str);
if (metaData != null) {
str2 = metaData.get("METADATA_KEY_BITRATE");
} else {
str2 = null;
}
}
}
return str2;
}
public static synchronized String getDuration(String str) {
String str2;
synchronized (MediaMetadataUtil.class) {
if (MetadataCache.mDataSource != null && MetadataCache.mDataSource.equals(str) && MetadataCache.mDuration != null) {
new StringBuilder("getduration from cache: ").append(MetadataCache.mDuration);
str2 = MetadataCache.mDuration;
} else {
Map<String, String> metaData = getMetaData(str);
if (metaData != null) {
str2 = metaData.get("METADATA_KEY_DURATION");
} else {
str2 = null;
}
}
}
return str2;
}
private static Map<String, String> getMetaData(String str) {
MediaPlayerMetadataRetriever.setMediaMetadataRetrieverPackName(MediaPlayerMetadataRetriever.SystemMediaMetadataRetrieverPackName);
if (MediaPlayerMetadataRetriever.createMediaMetadataRetriever(str) != null) {
Map<String, String> metadata = MediaPlayerMetadataRetriever.getMetadata();
if (metadata != null) {
MetadataCache.mDataSource = str;
MetadataCache.mBitrate = metadata.get("METADATA_KEY_BITRATE");
MetadataCache.mDuration = metadata.get("METADATA_KEY_DURATION");
new StringBuilder("retrieves the metadata from ").append(str).append(" success.");
}
MediaPlayerMetadataRetriever.release();
return metadata;
}
return null;
}
}