package com.tencent.mm.plugin.appbrand.jsapi.u.b;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.appbrand.jsapi.ah;
import com.tencent.mm.plugin.appbrand.jsapi.c;
import com.tencent.mm.plugin.appbrand.page.u;
import com.tencent.mm.plugin.appbrand.q;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.al;
import com.tencent.mm.sdk.platformtools.ap;
import java.util.Locale;
import org.json.JSONException;
import org.json.JSONObject;

public final class b implements g {
    c hcM;
    private ap ias;
    c idM;
    double idN;
    int idO;
    private String idP;

    public b(c cVar, c cVar2) {
        this.hcM = cVar2;
        this.idM = cVar;
    }

    public final void onVideoPlay() {
        AppMethodBeat.i(117375);
        try {
            this.idO = 0;
            JSONObject aFV = aFV();
            aFV.put("timeStamp", System.currentTimeMillis());
            a(new e((byte) 0), aFV);
            ab.i("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "start video update timer");
            if (this.ias == null) {
                ab.i("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "start video update timer, create new timer");
                this.ias = new ap(new 1(this), true);
            }
            this.ias.ae(250, 250);
            al.d(new 2(this));
            AppMethodBeat.o(117375);
        } catch (JSONException e) {
            ab.e("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "OnXWebVideoPlay fail", new Object[]{e});
            AppMethodBeat.o(117375);
        }
    }

    public final void onVideoPause() {
        AppMethodBeat.i(117376);
        try {
            a(new d((byte) 0), aFV());
        } catch (JSONException e) {
            ab.e("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "OnXWebVideoPause fail", new Object[]{e});
        }
        aFW();
        aGF();
        AppMethodBeat.o(117376);
    }

    public final void aGE() {
        AppMethodBeat.i(117377);
        try {
            a(new a((byte) 0), aFV());
        } catch (JSONException e) {
            ab.e("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "OnXWebVideoEnded fail", new Object[]{e});
        }
        aFW();
        aGF();
        AppMethodBeat.o(117377);
    }

    public final void onVideoWaiting() {
        AppMethodBeat.i(117378);
        try {
            JSONObject aFV = aFV();
            aFV.put("timeStamp", System.currentTimeMillis());
            a(new h((byte) 0), aFV);
            AppMethodBeat.o(117378);
        } catch (JSONException e) {
            ab.e("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "OnXWebVideoWaiting fail", new Object[]{e});
            AppMethodBeat.o(117378);
        }
    }

    public final void oJ(int i) {
        AppMethodBeat.i(117379);
        try {
            JSONObject aFV = aFV();
            aFV.put("buffered", i);
            a(new f((byte) 0), aFV);
            AppMethodBeat.o(117379);
        } catch (JSONException e) {
            ab.e("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "OnXWebVideoProgress fail", new Object[]{e});
            AppMethodBeat.o(117379);
        }
    }

    public final void I(String str, int i, int i2) {
        AppMethodBeat.i(117380);
        aFW();
        aGF();
        try {
            JSONObject aFV = aFV();
            aFV.put("errMsg", String.format(Locale.US, "%s(%d,%d)", new Object[]{str, Integer.valueOf(i), Integer.valueOf(i2)}));
            a(new b((byte) 0), aFV);
            AppMethodBeat.o(117380);
        } catch (JSONException e) {
            ab.e("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "OnXWebVideoError fail", new Object[]{e});
            AppMethodBeat.o(117380);
        }
    }

    public final void L(int i, int i2, int i3) {
        AppMethodBeat.i(117381);
        try {
            JSONObject aFV = aFV();
            aFV.put("width", i);
            aFV.put("height", i2);
            this.idN = (((double) i3) * 1.0d) / 1000.0d;
            aFV.put("duration", this.idN);
            a(new c((byte) 0), aFV);
            AppMethodBeat.o(117381);
        } catch (JSONException e) {
            ab.e("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "onXWebVideoLoadedMetaData fail", new Object[]{e});
            AppMethodBeat.o(117381);
        }
    }

    public final void Cd(String str) {
        this.idP = str;
    }

    public final void destroy() {
        AppMethodBeat.i(117382);
        aFW();
        AppMethodBeat.o(117382);
    }

    private void aFW() {
        AppMethodBeat.i(117383);
        ab.i("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "stop video update timer");
        if (this.ias != null) {
            this.ias.stopTimer();
        }
        AppMethodBeat.o(117383);
    }

    /* Access modifiers changed, original: final */
    public final JSONObject aFV() {
        AppMethodBeat.i(117384);
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("data", this.idP);
        AppMethodBeat.o(117384);
        return jSONObject;
    }

    /* Access modifiers changed, original: final */
    public final void a(ah ahVar, JSONObject jSONObject) {
        AppMethodBeat.i(117385);
        if (!((ahVar instanceof g) || (ahVar instanceof f))) {
            ab.i("MicroMsg.AppBrand.SameLayer.AppBrandVideoEventHandler", "dispatch event:%s, data:%s", new Object[]{ahVar.getName(), jSONObject.toString()});
        }
        ah AM = ahVar.AM(jSONObject.toString());
        if (this.hcM != null) {
            q qVar;
            u currentPageView;
            if (this.hcM instanceof q) {
                qVar = (q) this.hcM;
                qVar.b(AM);
                currentPageView = qVar.getCurrentPageView();
                if (currentPageView != null) {
                    currentPageView.b(AM);
                }
                AppMethodBeat.o(117385);
                return;
            } else if (this.hcM instanceof u) {
                currentPageView = (u) this.hcM;
                currentPageView.b(AM);
                qVar = currentPageView.xT();
                if (qVar != null) {
                    qVar.b(AM);
                }
                AppMethodBeat.o(117385);
                return;
            } else {
                this.hcM.b(AM);
            }
        }
        AppMethodBeat.o(117385);
    }

    private void aGF() {
        AppMethodBeat.i(117386);
        al.d(new 3(this));
        AppMethodBeat.o(117386);
    }
}
