package com.bytedance.sdk.openadsdk.yz.jnr.ro;

import com.bytedance.sdk.component.utils.wey;
import java.io.File;
import java.io.FileInputStream;
import nb.g;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class wu extends lb {
    private final com.bykv.vk.openvk.fm.fm.fm.lb.lb fm;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private long f7651lb;
    private long ro;
    private int yz;

    public wu(com.bykv.vk.openvk.fm.fm.fm.lb.lb lbVar) {
        this.fm = lbVar;
    }

    public void fm(int i10) {
        this.yz = i10;
    }

    public void ro(long j10) {
        this.f7651lb = j10;
    }

    public void fm(long j10) {
        this.ro = j10;
    }

    @Override // com.bytedance.sdk.openadsdk.yz.jnr.ro.lb
    public void fm(JSONObject jSONObject) {
        if (jSONObject == null) {
            return;
        }
        try {
            jSONObject.put("video_start_duration", this.ro);
            jSONObject.put("video_cache_size", this.f7651lb);
            jSONObject.put("is_auto_play", this.yz);
        } catch (Throwable th) {
            wey.lb("FeedPlayModel", th.getMessage());
        }
    }

    @Override // com.bytedance.sdk.openadsdk.yz.jnr.ro.lb
    public void fm(fm fmVar) throws Throwable {
        FileInputStream fileInputStream;
        if (this.fm.nt()) {
            String strJnr = this.fm.jnr();
            String strQhl = this.fm.qhl();
            File fileO = g.O(strJnr, strQhl);
            File fileJ = g.J(strJnr, strQhl);
            if (fileJ.exists()) {
                fileO = fileJ;
            }
            int i10 = -1;
            if (fileO.exists()) {
                long length = fileO.length();
                if (length > 0) {
                    FileInputStream fileInputStream2 = null;
                    try {
                        try {
                            fileInputStream = new FileInputStream(fileO);
                        } catch (Exception unused) {
                        }
                        try {
                            byte[] bArr = new byte[8];
                            long j10 = 0;
                            while (fileInputStream.read(bArr) == 8) {
                                long j11 = ((((long) bArr[1]) & 255) << 16) | ((((long) bArr[0]) & 255) << 24) | ((((long) bArr[2]) & 255) << 8) | (((long) bArr[3]) & 255);
                                if (bArr[4] != 109 || bArr[5] != 111 || bArr[6] != 111 || bArr[7] != 118) {
                                    long j12 = j11 - 8;
                                    if (j12 > 0 && fileInputStream.skip(j12) < j12) {
                                        break;
                                    } else {
                                        j10 += j11;
                                    }
                                } else {
                                    break;
                                }
                            }
                            i10 = (int) ((j10 * 100.0f) / length);
                            fileInputStream.close();
                        } catch (Exception unused2) {
                            fileInputStream2 = fileInputStream;
                            if (fileInputStream2 != null) {
                                fileInputStream2.close();
                            }
                            fmVar.yz().put("moov_box_pos", i10);
                        } catch (Throwable th) {
                            th = th;
                            fileInputStream2 = fileInputStream;
                            if (fileInputStream2 != null) {
                                try {
                                    fileInputStream2.close();
                                } catch (Exception unused3) {
                                }
                            }
                            throw th;
                        }
                    } catch (Exception unused4) {
                    } catch (Throwable th2) {
                        th = th2;
                    }
                }
            }
            try {
                fmVar.yz().put("moov_box_pos", i10);
            } catch (JSONException unused5) {
            }
        }
    }
}
