218 lines
7.4 KiB
Java
218 lines
7.4 KiB
Java
package com.ubt.jimu.widgets.player.widget;
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.os.Build;
|
|
import android.util.Log;
|
|
import android.view.SurfaceHolder;
|
|
import android.view.SurfaceView;
|
|
import android.view.View;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
import com.baidu.cloud.media.player.IMediaPlayer;
|
|
import com.ubt.jimu.widgets.player.widget.IRenderView;
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class SurfaceRenderView extends SurfaceView implements IRenderView {
|
|
private MeasureHelper a;
|
|
private SurfaceCallback b;
|
|
|
|
private static final class InternalSurfaceHolder implements IRenderView.ISurfaceHolder {
|
|
private SurfaceRenderView a;
|
|
private SurfaceHolder b;
|
|
|
|
public InternalSurfaceHolder(SurfaceRenderView surfaceRenderView, SurfaceHolder surfaceHolder) {
|
|
this.a = surfaceRenderView;
|
|
this.b = surfaceHolder;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView.ISurfaceHolder
|
|
public void a(IMediaPlayer iMediaPlayer) {
|
|
if (iMediaPlayer != null) {
|
|
iMediaPlayer.setDisplay(this.b);
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView.ISurfaceHolder
|
|
public IRenderView a() {
|
|
return this.a;
|
|
}
|
|
}
|
|
|
|
private static final class SurfaceCallback implements SurfaceHolder.Callback {
|
|
private SurfaceHolder a;
|
|
private boolean b;
|
|
private int c;
|
|
private int d;
|
|
private int e;
|
|
private WeakReference<SurfaceRenderView> f;
|
|
private Map<IRenderView.IRenderCallback, Object> g = new ConcurrentHashMap();
|
|
|
|
public SurfaceCallback(SurfaceRenderView surfaceRenderView) {
|
|
this.f = new WeakReference<>(surfaceRenderView);
|
|
}
|
|
|
|
public void a(IRenderView.IRenderCallback iRenderCallback) {
|
|
InternalSurfaceHolder internalSurfaceHolder;
|
|
this.g.put(iRenderCallback, iRenderCallback);
|
|
if (this.a != null) {
|
|
internalSurfaceHolder = new InternalSurfaceHolder(this.f.get(), this.a);
|
|
iRenderCallback.a(internalSurfaceHolder, this.d, this.e);
|
|
} else {
|
|
internalSurfaceHolder = null;
|
|
}
|
|
if (this.b) {
|
|
if (internalSurfaceHolder == null) {
|
|
internalSurfaceHolder = new InternalSurfaceHolder(this.f.get(), this.a);
|
|
}
|
|
iRenderCallback.a(internalSurfaceHolder, this.c, this.d, this.e);
|
|
}
|
|
}
|
|
|
|
public void b(IRenderView.IRenderCallback iRenderCallback) {
|
|
this.g.remove(iRenderCallback);
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder.Callback
|
|
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
|
|
this.a = surfaceHolder;
|
|
this.b = true;
|
|
this.c = i;
|
|
this.d = i2;
|
|
this.e = i3;
|
|
InternalSurfaceHolder internalSurfaceHolder = new InternalSurfaceHolder(this.f.get(), this.a);
|
|
Iterator<IRenderView.IRenderCallback> it = this.g.keySet().iterator();
|
|
while (it.hasNext()) {
|
|
it.next().a(internalSurfaceHolder, i, i2, i3);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder.Callback
|
|
public void surfaceCreated(SurfaceHolder surfaceHolder) {
|
|
this.a = surfaceHolder;
|
|
this.b = false;
|
|
this.c = 0;
|
|
this.d = 0;
|
|
this.e = 0;
|
|
Log.d("SurfaceRenderView", "surfaceCreated: " + surfaceHolder.getSurface());
|
|
InternalSurfaceHolder internalSurfaceHolder = new InternalSurfaceHolder(this.f.get(), this.a);
|
|
Iterator<IRenderView.IRenderCallback> it = this.g.keySet().iterator();
|
|
while (it.hasNext()) {
|
|
it.next().a(internalSurfaceHolder, 0, 0);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder.Callback
|
|
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
|
|
this.a = null;
|
|
this.b = false;
|
|
this.c = 0;
|
|
this.d = 0;
|
|
this.e = 0;
|
|
InternalSurfaceHolder internalSurfaceHolder = new InternalSurfaceHolder(this.f.get(), this.a);
|
|
Iterator<IRenderView.IRenderCallback> it = this.g.keySet().iterator();
|
|
while (it.hasNext()) {
|
|
it.next().a(internalSurfaceHolder);
|
|
}
|
|
}
|
|
}
|
|
|
|
public SurfaceRenderView(Context context) {
|
|
super(context);
|
|
a(context);
|
|
}
|
|
|
|
private void a(Context context) {
|
|
this.a = new MeasureHelper(this);
|
|
this.b = new SurfaceCallback(this);
|
|
getHolder().addCallback(this.b);
|
|
getHolder().setType(0);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public boolean a() {
|
|
return true;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public void b(int i, int i2) {
|
|
if (i <= 0 || i2 <= 0) {
|
|
return;
|
|
}
|
|
this.a.b(i, i2);
|
|
requestLayout();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public Bitmap getBitmap() {
|
|
return null;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public View getView() {
|
|
return this;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
@TargetApi(14)
|
|
public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
|
super.onInitializeAccessibilityEvent(accessibilityEvent);
|
|
accessibilityEvent.setClassName(SurfaceRenderView.class.getName());
|
|
}
|
|
|
|
@Override // android.view.View
|
|
@TargetApi(14)
|
|
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
|
|
super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
|
|
if (Build.VERSION.SDK_INT >= 14) {
|
|
accessibilityNodeInfo.setClassName(SurfaceRenderView.class.getName());
|
|
}
|
|
}
|
|
|
|
@Override // android.view.SurfaceView, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
this.a.a(i, i2);
|
|
setMeasuredDimension(this.a.b(), this.a.a());
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public void release() {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public void setAspectRatio(int i) {
|
|
this.a.a(i);
|
|
requestLayout();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public void setVideoRotation(int i) {
|
|
Log.e("", "SurfaceView doesn't support rotation (" + i + ")!\n");
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public void b(IRenderView.IRenderCallback iRenderCallback) {
|
|
this.b.a(iRenderCallback);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public void a(int i, int i2) {
|
|
if (i <= 0 || i2 <= 0) {
|
|
return;
|
|
}
|
|
this.a.c(i, i2);
|
|
getHolder().setFixedSize(i, i2);
|
|
requestLayout();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.player.widget.IRenderView
|
|
public void a(IRenderView.IRenderCallback iRenderCallback) {
|
|
this.b.b(iRenderCallback);
|
|
}
|
|
}
|