package com.ss.android.ugc.aweme.mediaplayer;

import X.0CB;
import X.0CH;
import X.0CN;
import X.0Gf;
import X.0Gp;
import X.1Bn;
import X.6Is;
import X.C5758OdF;
import X.C5759OdG;
import X.C5760OdH;
import X.C5761OdI;
import X.C5762OdJ;
import X.C5764OdL;
import X.C5765OdM;
import X.C5767OdO;
import android.graphics.SurfaceTexture;
import android.view.TextureView;
import com.bytedance.covode.number.Covode;

public class MediaPlayerModule implements TextureView.SurfaceTextureListener, 6Is {
    public String LIZ;
    public C5758OdF LIZIZ;
    public boolean LIZJ;
    public boolean LIZLLL;
    public boolean LJ;
    public C5765OdM LJFF;
    public TextureView.SurfaceTextureListener LJI;
    public 1Bn<C5767OdO> LJII;

    static {
        Covode.recordClassIndex(91970);
    }

    public void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_PAUSE) {
            onPause();
        } else if (r3 == 0CB.ON_RESUME) {
            onResume();
        } else if (r3 == 0CB.ON_DESTROY) {
            onDestroy();
        }
    }

    @0CN(LIZ = 0CB.ON_PAUSE)
    public void onPause() {
        LIZIZ();
    }

    @0CN(LIZ = 0CB.ON_RESUME)
    public void onResume() {
        LIZ();
    }

    public final void LIZ() {
        if (!this.LIZJ && !this.LIZLLL) {
            this.LIZIZ.LIZJ();
            this.LJII.postValue(new C5767OdO(4, true));
        }
    }

    public final void LIZIZ() {
        this.LIZIZ.LIZIZ();
        this.LJII.postValue(new C5767OdO(3, true));
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public void onDestroy() {
        this.LIZIZ.LIZIZ();
        this.LIZIZ.LIZLLL();
        this.LIZIZ.LJ();
        this.LJII.postValue(new C5767OdO(6, true));
    }

    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
        TextureView.SurfaceTextureListener surfaceTextureListener = this.LJI;
        if (surfaceTextureListener != null) {
            surfaceTextureListener.onSurfaceTextureUpdated(surfaceTexture);
        }
    }

    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        surfaceTexture.release();
        this.LIZIZ.LIZLLL();
        this.LJII.postValue(new C5767OdO(5, true));
        TextureView.SurfaceTextureListener surfaceTextureListener = this.LJI;
        if (surfaceTextureListener != null) {
            return surfaceTextureListener.onSurfaceTextureDestroyed(surfaceTexture);
        }
        return false;
    }

    public MediaPlayerModule(C5758OdF odF, C5765OdM odM) {
        1Bn<C5767OdO> r1 = new 1Bn<>();
        this.LJII = r1;
        this.LIZIZ = odF;
        this.LJFF = odM;
        r1.observeForever(new C5764OdL(this));
    }

    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
        TextureView.SurfaceTextureListener surfaceTextureListener = this.LJI;
        if (surfaceTextureListener != null) {
            surfaceTextureListener.onSurfaceTextureSizeChanged(surfaceTexture, i, i2);
        }
    }

    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
        TextureView.SurfaceTextureListener surfaceTextureListener = this.LJI;
        if (surfaceTextureListener != null) {
            surfaceTextureListener.onSurfaceTextureAvailable(surfaceTexture, i, i2);
        }
        0Gp.LIZ(new C5759OdG(this)).LIZ(new C5761OdI(this), 0Gp.LIZIZ, (0Gf) null).LIZ(new C5760OdH(this, surfaceTexture)).LIZ(new C5762OdJ(this), 0Gp.LIZIZ, (0Gf) null);
    }
}
