package com.tencent.mm.plugin.appbrand.jsapi.audio;

import android.text.TextUtils;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.appbrand.jsapi.a;
import com.tencent.mm.plugin.appbrand.jsapi.c;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import org.json.JSONObject;

public class h extends a {
    public static final int CTRL_INDEX = 297;
    public static final String NAME = "operateAudio";
    private k.a hAm;

    public final void a(c cVar, JSONObject jSONObject, int i) {
        long j = 0;
        AppMethodBeat.i(137747);
        if (!com.tencent.mm.plugin.appbrand.media.a.a.Ct(cVar.getAppId())) {
            ab.e("MicroMsg.Audio.JsApiOperateAudio", "can't do operateAudio, App is paused or background");
            cVar.M(i, j("fail:App is paused or background", null));
            AppMethodBeat.o(137747);
        } else if (jSONObject == null) {
            ab.e("MicroMsg.Audio.JsApiOperateAudio", "operateAudio data is null");
            cVar.M(i, j("fail:data is null", null));
            AppMethodBeat.o(137747);
        } else {
            ab.i("MicroMsg.Audio.JsApiOperateAudio", "operateAudio appId:%s, data:%s", new Object[]{cVar.getAppId(), jSONObject.toString()});
            String optString = jSONObject.optString("audioId");
            int optInt = jSONObject.optInt("currentTime", 0);
            String optString2 = jSONObject.optString("operationType");
            if (TextUtils.isEmpty(optString)) {
                ab.e("MicroMsg.Audio.JsApiOperateAudio", "audioId is empty");
                cVar.M(i, j("fail:audioId is empty", null));
                AppMethodBeat.o(137747);
            } else if (TextUtils.isEmpty(optString2)) {
                ab.e("MicroMsg.Audio.JsApiOperateAudio", "operationType is empty");
                cVar.M(i, j("fail:operationType is empty", null));
                AppMethodBeat.o(137747);
            } else {
                if (this.hAm == null) {
                    this.hAm = new k.a(this, cVar, i);
                }
                this.hAm.appId = cVar.getAppId();
                this.hAm.aCr();
                a aVar = new a(this, cVar, i);
                aVar.appId = cVar.getAppId();
                aVar.ckD = optString;
                aVar.csK = optInt;
                aVar.hAn = optString2;
                if (optString2.equalsIgnoreCase("play")) {
                    long optLong = jSONObject.optLong("timestamp", 0);
                    long currentTimeMillis = System.currentTimeMillis();
                    if (optLong > 0 && optLong < currentTimeMillis) {
                        j = currentTimeMillis - optLong;
                    }
                    aVar.fqP = j;
                    aVar.fqQ = currentTimeMillis;
                }
                com.tencent.mm.plugin.appbrand.media.a.c Cr = com.tencent.mm.plugin.appbrand.media.a.a.Cr(optString);
                if (Cr != null) {
                    aVar.hAo = Cr.hAo;
                    aVar.gSP = Cr.gSP;
                    aVar.ckz = Cr.ckz;
                }
                aVar.processName = ah.getProcessName();
                aVar.aCr();
                AppMethodBeat.o(137747);
            }
        }
    }
}
