package com.lynx.canvas.player;

import X.C1216Tnc;
import X.C1217Tnd;
import X.Jvy;
import X.Jvz;
import android.view.Surface;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.lynx.canvas.CanvasManager;
import com.lynx.canvas.SurfaceTextureWrapper;

public class PlayerContext {
    public C1216Tnc LIZ;
    public long LIZIZ;
    public double LIZJ;
    public boolean LIZLLL;
    public Surface LJ;
    public CanvasManager LJFF;

    static {
        Covode.recordClassIndex(46113);
    }

    public static native void nativeNotifyPlayerState(long j, int i, int[] iArr);

    public boolean getLoop() {
        C1216Tnc tnc = this.LIZ;
        if (tnc == null) {
            return false;
        }
        return tnc.LJIIIIZZ();
    }

    public void pause() {
        C1216Tnc tnc = this.LIZ;
        if (tnc != null) {
            tnc.LJFF();
        }
    }

    public void play() {
        C1216Tnc tnc = this.LIZ;
        if (tnc != null) {
            tnc.LJ();
        }
    }

    public double getCurrentTime() {
        C1216Tnc tnc = this.LIZ;
        if (tnc == null || !tnc.LJII()) {
            return 0.0d;
        }
        return this.LIZ.LJIIIZ();
    }

    public void release() {
        C1216Tnc tnc = this.LIZ;
        if (tnc != null) {
            tnc.LJI();
        }
        Surface surface = this.LJ;
        if (surface != null) {
            surface.release();
            this.LJ = null;
        }
        this.LIZIZ = 0;
    }

    public void setCurrentTime(double d) {
        C1216Tnc tnc = this.LIZ;
        if (tnc == null || !this.LIZLLL) {
            this.LIZJ = d;
        } else {
            tnc.LIZ(d);
        }
    }

    public void setLoop(boolean z) {
        C1216Tnc tnc = this.LIZ;
        if (tnc != null) {
            tnc.LIZ(z);
        }
    }

    public void setVolume(double d) {
        C1216Tnc tnc = this.LIZ;
        if (tnc != null) {
            tnc.LIZIZ(d);
        }
    }

    public void setupSurface(SurfaceTextureWrapper surfaceTextureWrapper) {
        Surface surface = new Surface(surfaceTextureWrapper.LIZ);
        this.LIZ.LIZ(surface);
        Surface surface2 = this.LJ;
        if (surface2 != null) {
            surface2.release();
        }
        this.LJ = surface;
    }

    public void load(String str) {
        C1216Tnc jvy;
        if (this.LIZ == null) {
            C1217Tnd iCanvasPlayerFactory = this.LJFF.getICanvasPlayerFactory();
            if (iCanvasPlayerFactory != null) {
                jvy = iCanvasPlayerFactory.LIZ();
            } else {
                jvy = new Jvy();
            }
            this.LIZ = jvy;
            jvy.LIZ((Jvz) new Jvz() {
                static {
                    Covode.recordClassIndex(46114);
                }

                public final void LIZ() {
                    MethodCollector.i(14530);
                    PlayerContext.nativeNotifyPlayerState(PlayerContext.this.LIZIZ, 1, (int[]) null);
                    MethodCollector.o(14530);
                }

                public final boolean LIZIZ() {
                    MethodCollector.i(14531);
                    PlayerContext.nativeNotifyPlayerState(PlayerContext.this.LIZIZ, 2, (int[]) null);
                    MethodCollector.o(14531);
                    return false;
                }

                public final void LIZJ() {
                    MethodCollector.i(14532);
                    PlayerContext.nativeNotifyPlayerState(PlayerContext.this.LIZIZ, 4, (int[]) null);
                    MethodCollector.o(14532);
                }

                public final void LIZLLL() {
                    MethodCollector.i(14533);
                    PlayerContext.nativeNotifyPlayerState(PlayerContext.this.LIZIZ, 3, (int[]) null);
                    MethodCollector.o(14533);
                }

                public final void LIZ(C1216Tnc tnc) {
                    MethodCollector.i(14529);
                    PlayerContext.this.LIZLLL = true;
                    if (PlayerContext.this.LIZJ != 0.0d) {
                        PlayerContext playerContext = PlayerContext.this;
                        playerContext.setCurrentTime(playerContext.LIZJ);
                    }
                    PlayerContext.nativeNotifyPlayerState(PlayerContext.this.LIZIZ, 0, new int[]{tnc.LIZ(), tnc.LIZIZ(), tnc.LIZJ(), tnc.LIZLLL()});
                    MethodCollector.o(14529);
                }
            });
        }
        this.LIZ.LIZ(this.LJFF.getContext(), str);
    }

    public PlayerContext(long j, CanvasManager canvasManager) {
        this.LIZIZ = j;
        this.LJFF = canvasManager;
    }

    public static PlayerContext create(long j, CanvasManager canvasManager) {
        return new PlayerContext(j, canvasManager);
    }
}
