QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

以下内容为反编译后的 LiveSdkPlayerHelper.java 源代码,内容仅作参考


package com.tencent.livesdk.livesdkplayer;

import android.content.Context;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import com.tencent.livesdk.livesdkplayer.IMediaPlayerMgr;
import com.tencent.livesdk.livesdkplayer.network.NetWorkManager;
import com.tencent.livesdk.livesdkplayer.network.NetWorkReceiver;
import com.tencent.livesdk.livesdkplayer.renderview.ITPPlayerVideoViewBase;
import com.tencent.livesdk.livesdkplayer.renderview.TPPlayerVideoView;
import com.tencent.livesdk.livesdkplayer.utils.UIUtil;
import com.tencent.mtt.R;
import com.tencent.thumbplayer.api.ITPPlayer;
import com.tencent.thumbplayer.api.TPPlayerMgr;
import com.tencent.thumbplayer.api.TPVideoFrameBuffer;
import com.tencent.thumbplayer.api.report.TPDefaultReportInfo;
import com.tencent.thumbplayer.api.report.TPLiveReportInfo;
import com.tencent.thumbplayer.api.report.TPVodReportInfo;
import com.tencent.thumbplayer.config.TPPlayerConfig;
import com.tencent.thumbplayer.utils.TPLogUtil;

public class LiveSdkPlayerHelper implements NetWorkReceiver.OnNetworkCallback {

    private ITPPlayerVideoViewBase f14539a;

    private IMediaPlayerMgr f14540b;

    private PlayerParams f14541c;

    private AVCatonReportParams f14542d;
    private PlayerStatusListener e;
    private LogAdapter j;
    private String l;
    private int m;
    private int f = 0;
    private boolean g = false;
    private int h = 0;
    private boolean i = false;
    private boolean k = false;
    private boolean n = false;
    private boolean o = false;
    private TPPlayerMgr.OnLogListener p = new TPPlayerMgr.OnLogListener() {
        @Override
        public int d(String str, String str2) {
            LiveSdkPlayerHelper.this.j.b(str, str2, new Object[0]);
            return 0;
        }

        @Override
        public int e(String str, String str2) {
            LiveSdkPlayerHelper.this.j.e(str, str2, new Object[0]);
            return 0;
        }

        @Override
        public int i(String str, String str2) {
            LiveSdkPlayerHelper.this.j.c(str, str2, new Object[0]);
            return 0;
        }

        @Override
        public int v(String str, String str2) {
            LiveSdkPlayerHelper.this.j.a(str, str2, new Object[0]);
            return 0;
        }

        @Override
        public int w(String str, String str2) {
            LiveSdkPlayerHelper.this.j.d(str, str2, new Object[0]);
            return 0;
        }
    };
    private Handler q = new Handler() {
        @Override
        public void handleMessage(Message message) {
            LiveSdkPlayerHelper.this.q.removeCallbacksAndMessages(null);
            if ((message != null || message.what == 100) && LiveSdkPlayerHelper.this.f14540b != null) {
                if (LiveSdkPlayerHelper.this.f14542d != null) {
                    long d2 = LiveSdkPlayerHelper.this.f14542d.d() - LiveSdkPlayerHelper.this.f14542d.k();
                    if (d2 <= 0) {
                        LiveSdkPlayerHelper.this.q.sendEmptyMessageDelayed(100, 1000L);
                        return;
                    }
                    if (d2 <= 5) {
                        LiveSdkPlayerHelper.this.f14542d.a(LiveSdkPlayerHelper.this.f14542d.a() + 1);
                    } else if (d2 <= 10) {
                        LiveSdkPlayerHelper.this.f14542d.b(LiveSdkPlayerHelper.this.f14542d.b() + 1);
                    } else {
                        LiveSdkPlayerHelper.this.f14542d.c(LiveSdkPlayerHelper.this.f14542d.c() + 1);
                    }
                    LiveSdkPlayerHelper.this.f14542d.i(LiveSdkPlayerHelper.this.f14542d.d());
                }
                LiveSdkPlayerHelper.this.q.sendEmptyMessageDelayed(100, 1000L);
            }
        }
    };
    private IMediaPlayerMgr.OnPreparedListener r = new IMediaPlayerMgr.OnPreparedListener() {
        @Override
        public void a(IMediaPlayerMgr iMediaPlayerMgr) {
            TPLogUtil.i("LiveSdkPlayerHelper", "onVideoPrepared:  调用 videoPlayer.start() 开始播放");
            if (LiveSdkPlayerHelper.this.e == null) {
                TPLogUtil.e("LiveSdkPlayerHelper", "player status listener is null");
                return;
            }
            if (LiveSdkPlayerHelper.this.f14539a == null) {
                return;
            }
            if (!LiveSdkPlayerHelper.this.o) {
                if (!LiveSdkPlayerHelper.this.k && LiveSdkPlayerHelper.this.d() > LiveSdkPlayerHelper.this.e()) {
                    LiveSdkPlayerHelper.this.f14539a.setRenderGravity(48);
                    ((View) LiveSdkPlayerHelper.this.f14539a).setPadding(0, LiveSdkPlayerHelper.this.f, 0, 0);
                    LiveSdkPlayerHelper.this.f14539a.setXYAxis(0);
                    LiveSdkPlayerHelper.this.g = true;
                } else {
                    LiveSdkPlayerHelper.this.f14539a.setRenderGravity(17);
                    ((View) LiveSdkPlayerHelper.this.f14539a).setPadding(0, 0, 0, 0);
                    LiveSdkPlayerHelper.this.f14539a.setXYAxis(2);
                }
                LiveSdkPlayerHelper.this.f14539a.a(LiveSdkPlayerHelper.this.d(), LiveSdkPlayerHelper.this.e());
            }
            LiveSdkPlayerHelper.this.e.a(LiveSdkPlayerHelper.this.f14539a, iMediaPlayerMgr.n(), iMediaPlayerMgr.o());
            LiveSdkPlayerHelper.this.e.a(iMediaPlayerMgr);
        }
    };
    private IMediaPlayerMgr.OnErrorListener s = new IMediaPlayerMgr.OnErrorListener() {
        @Override
        public void a(IMediaPlayerMgr iMediaPlayerMgr, int i, int i2, long j, long j2) {
            TPLogUtil.e("LiveSdkPlayerHelper", "onError: errorCode" + i2 + ", errorType " + i);
            if (i == 1103 || i == 1102 || i == 2001 || i == 1101) {
                if (LiveSdkPlayerHelper.this.e != null) {
                    LiveSdkPlayerHelper.this.e.a();
                }
                if (LiveSdkPlayerHelper.this.h < 3) {
                    TPLogUtil.e("LiveSdkPlayerHelper", "onError :  errorType = " + i + ", errorCode = " + i2 + ", 网络原因,尝试重试策略:当前已重试次数" + LiveSdkPlayerHelper.this.h);
                    try {
                        LiveSdkPlayerHelper.this.b();
                        LiveSdkPlayerHelper.this.l();
                        LiveSdkPlayerHelper.this.g();
                    } catch (Exception e) {
                        TPLogUtil.e("LiveSdkPlayerHelper", "retry exception:" + e.getMessage());
                        e.printStackTrace();
                    }
                    LiveSdkPlayerHelper.k(LiveSdkPlayerHelper.this);
                    return;
                }
            }
            if (LiveSdkPlayerHelper.this.e != null) {
                LiveSdkPlayerHelper.this.e.a(iMediaPlayerMgr, i2, "");
            }
        }
    };
    private IMediaPlayerMgr.OnInfoListener t = new IMediaPlayerMgr.OnInfoListener() {
        @Override
        public void a(IMediaPlayerMgr iMediaPlayerMgr, int i, long j, long j2, Object obj) {
            if (i == 3) {
                if (LiveSdkPlayerHelper.this.e != null) {
                    LiveSdkPlayerHelper.this.e.e();
                    return;
                }
                return;
            }
            if (i == 106) {
                if (LiveSdkPlayerHelper.this.e != null) {
                    LiveSdkPlayerHelper.this.e.b(LiveSdkPlayerHelper.this.f14540b);
                }
                LiveSdkPlayerHelper.this.f14542d.e(System.currentTimeMillis());
                LiveSdkPlayerHelper.this.f14542d.a(iMediaPlayerMgr.n(), iMediaPlayerMgr.o());
                LiveSdkPlayerHelper.this.q.removeCallbacksAndMessages(null);
                LiveSdkPlayerHelper.this.q.sendEmptyMessage(100);
                return;
            }
            if (i != 500) {
                if (i == 200) {
                    TPLogUtil.i("LiveSdkPlayerHelper", "onInfoListener 开始缓冲");
                    if (LiveSdkPlayerHelper.this.e != null) {
                        LiveSdkPlayerHelper.this.e.d(LiveSdkPlayerHelper.this.f14540b);
                        return;
                    }
                    return;
                }
                if (i != 201) {
                    return;
                }
                TPLogUtil.i("LiveSdkPlayerHelper", "onInfoListener 结束缓冲");
                if (LiveSdkPlayerHelper.this.e != null) {
                    LiveSdkPlayerHelper.this.e.e(LiveSdkPlayerHelper.this.f14540b);
                    return;
                }
                return;
            }
            if (LiveSdkPlayerHelper.this.f14539a == null) {
                return;
            }
            TPLogUtil.i("LiveSdkPlayerHelper", "width :" + iMediaPlayerMgr.n() + " height:" + iMediaPlayerMgr.o());
            if (iMediaPlayerMgr.n() > iMediaPlayerMgr.o()) {
                if (!LiveSdkPlayerHelper.this.g) {
                    if (LiveSdkPlayerHelper.this.k) {
                        LiveSdkPlayerHelper.this.f14539a.setRenderGravity(17);
                        ((View) LiveSdkPlayerHelper.this.f14539a).setPadding(0, 0, 0, 0);
                    } else {
                        LiveSdkPlayerHelper.this.f14539a.setRenderGravity(48);
                        ((View) LiveSdkPlayerHelper.this.f14539a).setPadding(0, LiveSdkPlayerHelper.this.f, 0, 0);
                    }
                }
                LiveSdkPlayerHelper.this.f14539a.setXYAxis(0);
                LiveSdkPlayerHelper.this.g = true;
            } else {
                LiveSdkPlayerHelper.this.f14539a.setRenderGravity(17);
                ((View) LiveSdkPlayerHelper.this.f14539a).setPadding(0, 0, 0, 0);
                LiveSdkPlayerHelper.this.f14539a.setXYAxis(2);
                LiveSdkPlayerHelper.this.g = false;
            }
            LiveSdkPlayerHelper.this.f14539a.a(iMediaPlayerMgr.n(), iMediaPlayerMgr.o());
        }
    };
    private IMediaPlayerMgr.OnCompletionListener u = new IMediaPlayerMgr.OnCompletionListener() {
        @Override
        public void a(IMediaPlayerMgr iMediaPlayerMgr) {
            TPLogUtil.i("LiveSdkPlayerHelper", "onCompletion: 视频播放结束");
            if (LiveSdkPlayerHelper.this.e != null) {
                LiveSdkPlayerHelper.this.e.c(LiveSdkPlayerHelper.this.f14540b);
            }
        }
    };
    private IMediaPlayerMgr.OnSeekCompleteListener v = new IMediaPlayerMgr.OnSeekCompleteListener() {
        @Override
        public void a(IMediaPlayerMgr iMediaPlayerMgr) {
            TPLogUtil.i("LiveSdkPlayerHelper", "onSeekComplete: " + iMediaPlayerMgr.l());
        }
    };
    private IMediaPlayerMgr.OnVideoFrameOutListener w = new IMediaPlayerMgr.OnVideoFrameOutListener() {
        @Override
        public void a(ITPPlayer iTPPlayer, TPVideoFrameBuffer tPVideoFrameBuffer) {
            LiveSdkPlayerHelper.this.f14542d.d((LiveSdkPlayerHelper.this.f14542d == null ? 0L : LiveSdkPlayerHelper.this.f14542d.d()) + 1);
        }
    };
    private IMediaPlayerMgr.OnSurfaceChangeListener x = new IMediaPlayerMgr.OnSurfaceChangeListener() {
        @Override
        public void a() {
            if (LiveSdkPlayerHelper.this.e != null) {
                LiveSdkPlayerHelper.this.e.c();
            }
        }

        @Override
        public void b() {
            if (LiveSdkPlayerHelper.this.e != null) {
                LiveSdkPlayerHelper.this.e.d();
            }
        }
    };

    public static class PlayerParams {

        public int f14553a = 2;

        public String f14554b;

        public String f14555c;

        public String f14556d;
        public String e;
        public long f;
        public long g;
        public int h;
        public byte[] i;
        public String j;
        public int k;

        public String a() {
            return a(this.f14553a);
        }

        public String a(int i) {
            this.f14553a = i;
            return i != 1 ? i != 3 ? this.f14555c : this.f14556d : this.e;
        }
    }

    public interface PlayerStatusListener {
        void a();

        void a(int i);

        void a(IMediaPlayerMgr iMediaPlayerMgr);

        void a(IMediaPlayerMgr iMediaPlayerMgr, int i, String str);

        void a(ITPPlayerVideoViewBase iTPPlayerVideoViewBase, int i, int i2);

        long b();

        void b(IMediaPlayerMgr iMediaPlayerMgr);

        void c();

        void c(IMediaPlayerMgr iMediaPlayerMgr);

        void d();

        void d(IMediaPlayerMgr iMediaPlayerMgr);

        void e();

        void e(IMediaPlayerMgr iMediaPlayerMgr);
    }

    static int k(LiveSdkPlayerHelper liveSdkPlayerHelper) {
        int i = liveSdkPlayerHelper.h;
        liveSdkPlayerHelper.h = i + 1;
        return i;
    }

    private void r() {
        PlayerStatusListener playerStatusListener;
        if (this.f14542d.e() <= 0) {
            return;
        }
        if (this.f14542d.g() <= 0 && (playerStatusListener = this.e) != null) {
            this.f14542d.f(playerStatusListener.b());
        }
        AVCatonReportManager.a().b().a(this.f14542d.a(), this.f14542d.b(), this.f14542d.c(), this.f14542d.d());
        AVCatonReport4Player b2 = AVCatonReportManager.a().b();
        String h = this.f14542d.h();
        String i = this.f14542d.i();
        String valueOf = String.valueOf(this.f14542d.g());
        PlayerParams playerParams = this.f14541c;
        b2.a(h, i, valueOf, "thumbsdk", "2.5.1.98", playerParams == null ? "" : playerParams.j);
        AVCatonReportManager.a().b().a(this.f14542d.e() - this.f14542d.j(), this.f14542d.f());
        AVCatonReportManager.a().b().a();
    }

    private void s() {
        this.f14542d = new AVCatonReportParams();
        this.f14540b.a(this.r);
        this.f14540b.a(this.u);
        this.f14540b.a(this.s);
        this.f14540b.a(this.t);
        this.f14540b.a(this.v);
        this.f14540b.a(this.w);
        this.f14540b.a(this.x);
        this.q.removeCallbacksAndMessages(null);
    }

    public void a() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                LiveSdkPlayerHelper.this.l();
            }
        }, "uninit_thumb_player").start();
        this.f14540b.h();
        TPLogUtil.i("LiveSdkPlayerHelper", "uninit");
        this.f14539a.a();
        this.f14539a = null;
        this.e = null;
        TPLogUtil.setOnLogListener(null);
        this.p = null;
        this.j = null;
        NetWorkManager.a().b(this);
    }

    @Override
    public void a(int i) {
        TPLogUtil.i("LiveSdkPlayerHelper", "netWorkChange netStatus: " + i);
        PlayerStatusListener playerStatusListener = this.e;
        if (playerStatusListener != null) {
            playerStatusListener.a(i);
        }
    }

    public void a(Context context) {
        if (this.n) {
            TPPlayerMgr.initSdk(context, this.l, this.m);
            TPLogUtil.i("LiveSdkPlayerHelper", "init sdk need init platform is :" + this.n);
        }
        NetWorkManager.a().a(context);
        this.f14540b = new MediaPlayerMgr(context);
        TPPlayerConfig.setP2PEnable(false);
        s();
        NetWorkManager.a().a(this);
    }

    public void a(FrameLayout frameLayout, boolean z) {
        if (frameLayout == null) {
            throw new IllegalArgumentException("video container is null!!!");
        }
        this.g = false;
        ITPPlayerVideoViewBase iTPPlayerVideoViewBase = this.f14539a;
        if ((iTPPlayerVideoViewBase instanceof TPPlayerVideoView) && ((TPPlayerVideoView) iTPPlayerVideoViewBase).getParent() != null) {
            ViewParent parent = ((TPPlayerVideoView) this.f14539a).getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView((TPPlayerVideoView) this.f14539a);
            }
        }
        if (this.f14540b.b()) {
            TPLogUtil.i("LiveSdkPlayerHelper", "readyPlay is playing and stop");
            this.f14539a = null;
        }
        if (this.f14539a == null) {
            this.f14539a = new TPPlayerVideoView(frameLayout.getContext(), true, true, true);
        }
        View view = (View) this.f14539a;
        view.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        view.setVisibility(0);
        view.setId(R.id.thumb_player_container);
        frameLayout.addView(view);
        this.f14540b.a(this.f14539a);
        if (d() <= 0 || e() <= 0) {
            this.f14539a.setRenderGravity(17);
            ((View) this.f14539a).setPadding(0, 0, 0, 0);
            this.f14539a.setXYAxis(2);
        } else {
            if (this.k != z) {
                if (!z && d() > e()) {
                    this.f14539a.setRenderGravity(48);
                    ((View) this.f14539a).setPadding(0, this.f, 0, 0);
                    this.f14539a.setXYAxis(0);
                    this.g = true;
                } else {
                    this.f14539a.setRenderGravity(17);
                    ((View) this.f14539a).setPadding(0, 0, 0, 0);
                    this.f14539a.setXYAxis(2);
                }
            }
            this.f14539a.a(d(), e());
        }
        this.k = z;
        TPLogUtil.i("LiveSdkPlayerHelper", "readyPlay");
    }

    public void a(PlayerParams playerParams) {
        TPDefaultReportInfo tPVodReportInfo;
        PlayerParams playerParams2 = this.f14541c;
        if (playerParams2 != null && playerParams != null && !TextUtils.isEmpty(playerParams2.a()) && !this.f14541c.a().equals(playerParams.a())) {
            this.h = 0;
        }
        this.f14541c = playerParams;
        PlayerParams playerParams3 = this.f14541c;
        if (playerParams3 == null) {
            return;
        }
        if (playerParams3.k == 0) {
            tPVodReportInfo = new TPLiveReportInfo();
        } else {
            if (this.f14541c.k != 1) {
                TPLogUtil.i("LiveSdkPlayerHelper", "setParams: setReportInfoGetter null");
                return;
            }
            tPVodReportInfo = new TPVodReportInfo();
        }
        this.f14540b.a(tPVodReportInfo);
    }

    public void a(PlayerStatusListener playerStatusListener) {
        this.e = playerStatusListener;
    }

    public void a(LogAdapter logAdapter) {
        this.j = logAdapter;
        TPLogUtil.setOnLogListener(this.p);
    }

    public void a(String str) {
        this.f14540b.b(str);
    }

    public void a(String str, int i, boolean z) {
        this.l = str;
        this.m = i;
        this.n = z;
    }

    public void a(boolean z) {
        this.f14540b.a(z);
    }

    public void b() {
        TPLogUtil.i("LiveSdkPlayerHelper", "reset");
        this.f14540b.i();
    }

    public void b(int i) {
        Object obj;
        this.f = i;
        if (this.f != 0 || (obj = this.f14539a) == null) {
            return;
        }
        this.f = Math.max(UIUtil.a(((View) obj).getContext()) / 5, UIUtil.b(((View) this.f14539a).getContext()) / 5);
    }

    public void b(boolean z) {
        if (this.g) {
            this.o = z;
            ITPPlayerVideoViewBase iTPPlayerVideoViewBase = this.f14539a;
            if (z) {
                iTPPlayerVideoViewBase.setRenderGravity(17);
                ((View) this.f14539a).setPadding(0, 0, 0, 0);
            } else {
                iTPPlayerVideoViewBase.setRenderGravity(48);
                ((View) this.f14539a).setPadding(0, this.f, 0, 0);
            }
            TPLogUtil.i("LiveSdkPlayerHelper", "onScreenOrientationChange landscape: " + z + " offsetY:" + this.f);
            this.f14539a.setXYAxis(0);
        }
    }

    public String c() {
        return this.f14541c.a();
    }

    public void c(int i) {
        this.f14540b.a(i);
    }

    public int d() {
        return this.f14540b.n();
    }

    public int e() {
        return this.f14540b.o();
    }

    public Rect f() {
        return this.f14539a.getDisplayViewRect();
    }

    public void g() {
        if (this.f14541c == null) {
            return;
        }
        s();
        this.f14542d.a(this.f14541c.a(), this.f14541c.g);
        this.f14542d.g(System.currentTimeMillis());
        this.f14540b.a(this.f14541c.a());
        TPLogUtil.i("LiveSdkPlayerHelper", "openPlay");
    }

    public void h() {
        this.f14540b.a();
    }

    public boolean i() {
        return this.f14540b.b();
    }

    public boolean j() {
        return this.f14540b.c();
    }

    public void k() {
        this.f14540b.e();
    }

    public void l() {
        this.f14540b.g();
        this.f14542d.h(System.currentTimeMillis());
        this.q.removeCallbacksAndMessages(null);
        r();
        this.f14542d.a("", 0L);
    }

    public void m() {
        this.f14540b.f();
    }

    public void n() {
        if (this.i) {
            g();
        } else {
            this.f14540b.d();
        }
    }

    public long o() {
        return this.f14540b.k();
    }

    public long p() {
        return this.f14540b.l();
    }

    public PlayerParams q() {
        return this.f14541c;
    }
}