package com.ss.android.ugc.aweme.live.alphaplayer.controller;

import X.0CB;
import X.0CH;
import X.0CN;
import X.0HH;
import X.6Is;
import X.C0799Tgt;
import X.C1094Tle;
import X.C1095Tlf;
import X.C1098Tli;
import X.Htc;
import X.INM;
import X.INQ;
import X.INR;
import X.INZ;
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import com.bytedance.covode.number.Covode;
import com.bytedance.ugc.glue.monitor.UGCMonitor;
import com.ss.android.ugc.aweme.live.alphaplayer.Configuration;
import com.ss.android.ugc.aweme.live.alphaplayer.listener.AlphaPlayerAction;
import com.ss.android.ugc.aweme.live.alphaplayer.listener.IMonitor;
import com.ss.android.ugc.aweme.live.alphaplayer.listener.IProgressListener;
import com.ss.android.ugc.aweme.live.alphaplayer.model.DataSource;
import com.ss.android.ugc.aweme.live.alphaplayer.model.DataSource$ScaleType;
import com.ss.android.ugc.aweme.live.alphaplayer.model.MaskSrc;
import com.ss.android.ugc.aweme.live.alphaplayer.model.VideoInfo;
import com.ss.android.ugc.aweme.live.alphaplayer.player.AbsPlayer;
import com.ss.android.ugc.aweme.live.alphaplayer.player.DefaultSystemPlayer;
import com.ss.android.ugc.aweme.live.alphaplayer.player.IMediaPlayer;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class PlayerController implements Handler.Callback, 6Is, IPlayerController {
    public int actualHeight = 0;
    public int actualWidth = 0;
    public AlphaPlayerAction alphaPlayerAction;
    public C1094Tle alphaVideoView;
    public boolean autoRelease = true;
    public Context context;
    public C1098Tli customPrepareListener;
    public IMediaPlayer.OnErrorListener<AbsPlayer<AbsPlayer>> errorListener = new IMediaPlayer.OnErrorListener<AbsPlayer<AbsPlayer>>() {
        static {
            Covode.recordClassIndex(91048);
        }

        public final /* synthetic */ void onError(Object obj, int i, int i2, String str) {
            PlayerController.this.monitor(false, i, i2, "mediaPlayer error, info:".concat(String.valueOf(str)));
            PlayerController.this.emitEndSignal();
        }
    };
    public INQ firstGLFrameListener;
    public volatile boolean isAttached = false;
    public boolean isIntentPrepare;
    public boolean isLooping;
    public boolean isPlaying;
    public Handler mainHandler = new Handler(Looper.getMainLooper());
    public List<MaskSrc> masks = new ArrayList();
    public IMediaPlayer<AbsPlayer<AbsPlayer>> mediaPlayer;
    public long messageId;
    public IMonitor monitor;
    public 0CH owner = null;
    public HandlerThread playThread;
    public IMediaPlayer.OnPreparedListener<AbsPlayer<AbsPlayer>> preparedListener = new IMediaPlayer.OnPreparedListener<AbsPlayer<AbsPlayer>>() {
        static {
            Covode.recordClassIndex(91047);
        }

        public final /* synthetic */ void onPrepared(Object obj) {
            PlayerController.this.sendMessage(PlayerController.getMessage(2, (Object) null));
        }
    };
    public final C0799Tgt progressHelper = new C0799Tgt();
    public C1095Tlf state = C1095Tlf.NOT_PREPARED;
    public int totalFrame = 0;
    public int version = 0;
    public Handler workHandler;

    static {
        Covode.recordClassIndex(91042);
    }

    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_STOP) {
            onStop();
        } else if (r3 == 0CB.ON_DESTROY) {
            onDestroy();
        }
    }

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

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

    @0CN(LIZ = 0CB.ON_STOP)
    public void onStop() {
        stop();
    }

    public void cancel() {
        sendMessage(getMessage(12, (Object) null));
    }

    public int getDuration() {
        IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer = this.mediaPlayer;
        if (iMediaPlayer == null) {
            return -1;
        }
        try {
            return iMediaPlayer.getVideoInfo().getDuration();
        } catch (Exception unused) {
            return -1;
        }
    }

    public String getPlayerType() {
        IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer = this.mediaPlayer;
        if (iMediaPlayer != null) {
            return iMediaPlayer.getPlayerSimpleName();
        }
        return "unknown";
    }

    public View getView() {
        C1094Tle tle = this.alphaVideoView;
        if (tle != null) {
            return tle.getView();
        }
        return null;
    }

    public boolean isPlaying() {
        IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer = this.mediaPlayer;
        if (iMediaPlayer == null || !iMediaPlayer.isPlaying()) {
            return false;
        }
        return true;
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public void onDestroy() {
        sendMessage(getMessage(6, (Object) null));
    }

    public void pause() {
        sendMessage(getMessage(3, (Object) null));
    }

    public void reset() {
        sendMessage(getMessage(9, (Object) null));
    }

    public void resume() {
        sendMessage(getMessage(4, (Object) null));
    }

    public void stop() {
        sendMessage(getMessage(5, (Object) null));
    }

    public void emitEndSignal() {
        this.isPlaying = false;
        this.messageId = 0;
        this.mainHandler.post(new Runnable() {
            static {
                Covode.recordClassIndex(91043);
            }

            public final void run() {
                if (PlayerController.this.alphaPlayerAction != null) {
                    PlayerController.this.alphaPlayerAction.endAction();
                }
            }
        });
        this.progressHelper.LIZIZ();
    }

    public void release() {
        sendMessage(getMessage(6, (Object) null));
        0CH r0 = this.owner;
        if (r0 != null) {
            r0.getLifecycle().LIZIZ(this);
            this.owner = null;
        }
    }

    /* renamed from: com.ss.android.ugc.aweme.live.alphaplayer.controller.PlayerController$8  reason: invalid class name */
    public static /* synthetic */ class AnonymousClass8 {
        public static final /* synthetic */ int[] LIZ;

        /* JADX WARNING: Can't wrap try/catch for region: R(10:0|1|2|3|4|5|6|7|8|10) */
        /* JADX WARNING: Can't wrap try/catch for region: R(8:0|1|2|3|4|5|6|(3:7|8|10)) */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0018 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x0023 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x002e */
        static {
            /*
                r0 = 91050(0x163aa, float:1.27588E-40)
                com.bytedance.covode.number.Covode.recordClassIndex(r0)
                X.Tlf[] r0 = X.C1095Tlf.values()
                int r0 = r0.length
                int[] r2 = new int[r0]
                LIZ = r2
                X.Tlf r0 = X.C1095Tlf.PREPARED     // Catch:{ NoSuchFieldError -> 0x0018 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0018 }
                r0 = 1
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0018 }
            L_0x0018:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x0023 }
                X.Tlf r0 = X.C1095Tlf.PAUSED     // Catch:{ NoSuchFieldError -> 0x0023 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0023 }
                r0 = 2
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0023 }
            L_0x0023:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x002e }
                X.Tlf r0 = X.C1095Tlf.NOT_PREPARED     // Catch:{ NoSuchFieldError -> 0x002e }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x002e }
                r0 = 3
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x002e }
            L_0x002e:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x0039 }
                X.Tlf r0 = X.C1095Tlf.STOPPED     // Catch:{ NoSuchFieldError -> 0x0039 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0039 }
                r0 = 4
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0039 }
            L_0x0039:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.live.alphaplayer.controller.PlayerController.AnonymousClass8.<clinit>():void");
        }
    }

    private void initMediaPlayer() {
        try {
            this.mediaPlayer.initMediaPlayer();
        } catch (Exception e) {
            monitorInit(e);
            DefaultSystemPlayer defaultSystemPlayer = new DefaultSystemPlayer();
            defaultSystemPlayer.initMediaPlayer();
            this.mediaPlayer = defaultSystemPlayer;
        }
        this.mediaPlayer.setScreenOnWhilePlaying(true);
        this.mediaPlayer.setLooping(this.isLooping);
        this.mediaPlayer.setOnFirstFrameListener(new IMediaPlayer.OnFirstFrameListener<AbsPlayer<AbsPlayer>>() {
            static {
                Covode.recordClassIndex(91044);
            }

            public final /* synthetic */ void onFirstFrame(Object obj) {
                PlayerController.this.alphaVideoView.LIZ();
            }
        });
        this.mediaPlayer.setOnCompletionListener(new IMediaPlayer.OnCompletionListener<AbsPlayer<AbsPlayer>>() {
            static {
                Covode.recordClassIndex(91045);
            }

            public final /* synthetic */ void onCompletion(Object obj) {
                if (!PlayerController.this.isAttached || !PlayerController.this.isLooping) {
                    if (PlayerController.this.autoRelease) {
                        PlayerController.this.alphaVideoView.LIZIZ();
                        PlayerController.this.masks.clear();
                    }
                    PlayerController.this.state = C1095Tlf.PAUSED;
                    PlayerController.this.monitor(true, (String) null);
                    PlayerController.this.emitEndSignal();
                }
            }
        });
    }

    private void parseVideoSize() {
        if (this.version <= 0) {
            VideoInfo videoInfo = this.mediaPlayer.getVideoInfo();
            this.actualWidth = videoInfo.getVideoWidth() / 2;
            this.actualHeight = videoInfo.getVideoHeight();
        }
        this.alphaVideoView.LIZ((float) this.actualWidth, (float) this.actualHeight);
        final DataSource$ScaleType scaleType = this.alphaVideoView.getScaleType();
        this.mainHandler.post(new Runnable() {
            static {
                Covode.recordClassIndex(91046);
            }

            public final void run() {
                if (PlayerController.this.alphaPlayerAction != null) {
                    PlayerController.this.alphaPlayerAction.onVideoSizeChange(PlayerController.this.actualWidth, PlayerController.this.actualHeight, scaleType);
                }
            }
        });
    }

    private void prepareAsync() {
        if (this.mediaPlayer != null) {
            if (this.state == C1095Tlf.NOT_PREPARED || this.state == C1095Tlf.STOPPED) {
                this.mediaPlayer.setOnPreparedListener(this.preparedListener);
                this.mediaPlayer.setOnErrorListener(this.errorListener);
                this.mediaPlayer.prepareAsync();
            }
        }
    }

    public int getCurFrame() {
        if (this.mediaPlayer == null || this.totalFrame == 0) {
            return -1;
        }
        float duration = (float) getDuration();
        if (duration <= 0.0f) {
            return -1;
        }
        float currentPosition = ((float) this.mediaPlayer.getCurrentPosition()) / duration;
        if (currentPosition > 1.0f) {
            return -1;
        }
        return (int) Math.ceil((double) (currentPosition * ((float) this.totalFrame)));
    }

    public void startPlay() {
        if (this.mediaPlayer != null) {
            int i = AnonymousClass8.LIZ[this.state.ordinal()];
            if (i == 1) {
                this.mediaPlayer.start();
                this.isPlaying = true;
                this.state = C1095Tlf.STARTED;
                this.mainHandler.post(new Runnable() {
                    static {
                        Covode.recordClassIndex(91049);
                    }

                    public final void run() {
                        if (PlayerController.this.alphaPlayerAction != null) {
                            PlayerController.this.alphaPlayerAction.startAction();
                        }
                    }
                });
                this.progressHelper.LIZ();
            } else if (i == 2) {
                this.mediaPlayer.start();
                this.state = C1095Tlf.STARTED;
                this.progressHelper.LIZ();
            } else if (i == 3 || i == 4) {
                try {
                    prepareAsync();
                } catch (Exception e) {
                    0HH.LIZ(e);
                    monitor(false, "prepare and start MediaPlayer failure.");
                    emitEndSignal();
                }
            }
        }
    }

    public void setMonitor(IMonitor iMonitor) {
        this.monitor = iMonitor;
    }

    public void setPrepareListener(C1098Tli tli) {
        this.customPrepareListener = tli;
    }

    public IPlayerController withVideoAction(AlphaPlayerAction alphaPlayerAction2) {
        this.alphaPlayerAction = alphaPlayerAction2;
        return this;
    }

    public void seekTo(int i) {
        IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer = this.mediaPlayer;
        if (iMediaPlayer != null) {
            iMediaPlayer.seekTo(i);
        }
    }

    public void sendMessage(Message message) {
        sendMessage(message, 0);
    }

    public void setFirstGLFrameListener(INQ inq) {
        this.firstGLFrameListener = inq;
        this.alphaVideoView.setFirstGLFrameListener(inq);
    }

    public void start(DataSource dataSource) {
        startWithLastFrameHold(dataSource, false);
    }

    public void attachAlphaView(ViewGroup viewGroup) {
        C1094Tle tle = this.alphaVideoView;
        if (tle != null && tle.LIZ(viewGroup)) {
            this.isAttached = true;
        }
    }

    public void detachAlphaView(ViewGroup viewGroup) {
        C1094Tle tle = this.alphaVideoView;
        if (tle != null && tle.LIZIZ(viewGroup)) {
            this.isAttached = false;
        }
    }

    public void setMask(MaskSrc maskSrc) {
        sendMessage(getMessage(11, maskSrc));
    }

    public void setSurface(Surface surface) {
        sendMessage(getMessage(7, surface));
    }

    public void setVisibility(int i) {
        this.alphaVideoView.setVisibility(i);
        if (i == 0) {
            this.alphaVideoView.bringToFront();
        }
    }

    private void initPlayer(IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer) {
        if (iMediaPlayer == null) {
            this.mediaPlayer = new DefaultSystemPlayer();
        } else {
            this.mediaPlayer = iMediaPlayer;
        }
        this.progressHelper.LIZ = this.mediaPlayer;
        sendMessage(getMessage(10, (Object) null));
    }

    private void monitorInit(Exception exc) {
        String str;
        IMonitor iMonitor = this.monitor;
        if (iMonitor != null) {
            IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer = this.mediaPlayer;
            if (iMediaPlayer != null) {
                str = iMediaPlayer.getPlayerSimpleName();
            } else {
                str = "unknown";
            }
            iMonitor.monitorInit(str, exc);
        }
    }

    private int getOrientation(Context context2) {
        if (!(context2 instanceof Activity)) {
            return context2.getResources().getConfiguration().orientation;
        }
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((Activity) context2).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        if (displayMetrics.widthPixels < displayMetrics.heightPixels) {
            return 1;
        }
        return 2;
    }

    private void initAlphaView(int i) {
        if (i == 1) {
            this.alphaVideoView = new INR(this.context);
        } else {
            this.alphaVideoView = new INZ(this.context);
        }
        this.alphaVideoView.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
        this.alphaVideoView.setPlayerController(this);
        this.alphaVideoView.setVideoRenderer(new INM(this.alphaVideoView));
    }

    private void setDataSource(DataSource dataSource) {
        try {
            setVideoFromFile(dataSource);
        } catch (Exception e) {
            0HH.LIZ(e);
            emitEndSignal();
            monitor(false, "alphaVideoView set dataSource failure:" + Log.getStackTraceString(e));
        }
    }

    private void setVideoFromFile(DataSource dataSource) {
        String path;
        if (!this.isAttached) {
            monitor(false, "alphaVideoView is not attach");
            emitEndSignal();
            return;
        }
        this.mediaPlayer.reset();
        this.state = C1095Tlf.NOT_PREPARED;
        int i = this.context.getResources().getConfiguration().orientation;
        DataSource.DataInfo dataInfo = dataSource.getDataInfo(i);
        if (dataInfo == null || TextUtils.isEmpty(dataInfo.getPath()) || !new File(dataInfo.getPath()).exists()) {
            if (1 == i) {
                StringBuilder sb = new StringBuilder("dataPath is empty or File is not exists. path: ");
                if (dataInfo == null) {
                    path = "null";
                } else {
                    path = dataInfo.getPath();
                }
                sb.append(path);
                monitor(false, sb.toString());
            }
            emitEndSignal();
            return;
        }
        this.alphaVideoView.setConfigParams(dataInfo);
        this.alphaVideoView.LIZ(this.masks);
        this.mediaPlayer.setDataSource(dataInfo.getPath());
        boolean loop = dataSource.getLoop();
        this.isLooping = loop;
        this.mediaPlayer.setLooping(loop);
        this.totalFrame = dataInfo.getTotalFrame();
        this.actualWidth = dataInfo.getActualWidth();
        this.actualHeight = dataInfo.getActualHeight();
        this.version = dataInfo.getVersion();
        this.autoRelease = dataSource.getAutoRelease();
        if (this.alphaVideoView.LIZJ()) {
            prepareAsync();
        } else {
            this.isIntentPrepare = true;
        }
    }

    public boolean handleMessage(Message message) {
        switch (message.what) {
            case 1:
                if (message.obj instanceof DataSource) {
                    Handler handler = this.workHandler;
                    if (handler != null) {
                        handler.removeMessages(8);
                    }
                    setDataSource((DataSource) message.obj);
                    break;
                }
                break;
            case 2:
                try {
                    parseVideoSize();
                    this.state = C1095Tlf.PREPARED;
                    C1098Tli tli = this.customPrepareListener;
                    if (tli == null || !tli.LIZ()) {
                        startPlay();
                        break;
                    }
                } catch (Exception e) {
                    emitEndSignal();
                    monitor(false, "start video failure:" + Log.getStackTraceString(e));
                    break;
                }
            case UGCMonitor.STATUS_RESPONSE:
                if (this.mediaPlayer != null && this.state == C1095Tlf.STARTED) {
                    this.mediaPlayer.pause();
                    this.progressHelper.LIZIZ();
                    this.state = C1095Tlf.PAUSED;
                    break;
                }
            case UGCMonitor.STATUS_FINISH:
                if (!this.isPlaying) {
                    if (this.isIntentPrepare) {
                        try {
                            prepareAsync();
                            this.isIntentPrepare = false;
                            break;
                        } catch (Exception e2) {
                            0HH.LIZ(e2);
                            monitor(false, "RESUME: prepare and start MediaPlayer failure.");
                            emitEndSignal();
                            break;
                        }
                    }
                } else {
                    startPlay();
                    break;
                }
                break;
            case 5:
                if (this.mediaPlayer != null && (this.state == C1095Tlf.STARTED || this.state == C1095Tlf.PAUSED)) {
                    this.mediaPlayer.pause();
                    this.progressHelper.LIZIZ();
                    this.state = C1095Tlf.PAUSED;
                    break;
                }
            case 6:
                this.alphaVideoView.onPause();
                this.progressHelper.LIZIZ();
                this.progressHelper.LIZJ();
                if (this.mediaPlayer != null) {
                    if (this.state == C1095Tlf.STARTED) {
                        this.mediaPlayer.pause();
                        this.state = C1095Tlf.PAUSED;
                    }
                    if (this.state == C1095Tlf.PAUSED) {
                        this.mediaPlayer.stop();
                        this.state = C1095Tlf.STOPPED;
                    }
                    this.mediaPlayer.release();
                    this.alphaVideoView.LIZLLL();
                    this.state = C1095Tlf.RELEASE;
                    HandlerThread handlerThread = this.playThread;
                    if (handlerThread != null) {
                        handlerThread.quit();
                        this.playThread.interrupt();
                        break;
                    }
                } else {
                    this.state = C1095Tlf.NOT_PREPARED;
                    return true;
                }
                break;
            case 7:
                try {
                    this.mediaPlayer.setSurface((Surface) message.obj);
                    break;
                } catch (Exception unused) {
                    emitEndSignal();
                    monitor(false, "surface has been released");
                    break;
                }
            case 9:
                IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer = this.mediaPlayer;
                if (iMediaPlayer != null) {
                    iMediaPlayer.reset();
                    this.progressHelper.LIZIZ();
                    this.state = C1095Tlf.NOT_PREPARED;
                    this.isPlaying = false;
                    break;
                }
                break;
            case 10:
                initMediaPlayer();
                break;
            case 11:
                if (message.obj instanceof MaskSrc) {
                    MaskSrc maskSrc = (MaskSrc) message.obj;
                    if (maskSrc.getType() == 0) {
                        try {
                            maskSrc.setBitmap(Htc.LIZ(maskSrc));
                        } catch (OutOfMemoryError unused2) {
                        }
                    }
                    if (maskSrc.getBitmap() != null) {
                        maskSrc.setWidth(maskSrc.getBitmap().getWidth());
                        maskSrc.setHeight(maskSrc.getBitmap().getHeight());
                        this.masks.add(maskSrc);
                        break;
                    }
                }
                break;
            case 12:
                IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer2 = this.mediaPlayer;
                if (iMediaPlayer2 != null) {
                    iMediaPlayer2.stop();
                    this.state = C1095Tlf.STOPPED;
                    this.isPlaying = false;
                    this.progressHelper.LIZIZ();
                    C1094Tle tle = this.alphaVideoView;
                    if (tle != null) {
                        tle.LIZIZ();
                        break;
                    }
                }
                break;
        }
        return true;
    }

    public void monitor(boolean z, String str) {
        monitor(z, 0, 0, str);
    }

    public void setProgressListener(IProgressListener iProgressListener, long j) {
        this.progressHelper.LIZ(iProgressListener, j);
    }

    public static Message getMessage(int i, Object obj) {
        Message obtain = Message.obtain();
        obtain.what = i;
        obtain.obj = obj;
        return obtain;
    }

    public static PlayerController get(Configuration configuration, IMediaPlayer iMediaPlayer) {
        return new PlayerController(configuration.getContext(), configuration.getLifecycleOwner(), iMediaPlayer, configuration.getAlphaVideoViewType(), configuration.getThreadName());
    }

    private void sendMessage(Message message, long j) {
        HandlerThread handlerThread = this.playThread;
        if (handlerThread != null && handlerThread.isAlive() && !this.playThread.isInterrupted()) {
            if (this.workHandler == null) {
                this.workHandler = new Handler(this.playThread.getLooper(), this);
            }
            this.workHandler.sendMessageDelayed(message, j);
        }
    }

    public void startWithLastFrameHold(DataSource dataSource, boolean z) {
        this.alphaVideoView.setLastFrameHold(z);
        DataSource copy = DataSource.copy(dataSource);
        this.messageId = dataSource.getMessageId();
        if (dataSource.isValid()) {
            setVisibility(0);
            sendMessage(getMessage(1, copy));
            return;
        }
        emitEndSignal();
        monitor(false, "dataSource is invalid. ErrorInfo: " + copy.getErrorInfo());
    }

    private void init(Context context2, 0CH r4, String str) {
        this.context = context2;
        this.owner = r4;
        if (r4 != null) {
            r4.getLifecycle().LIZ(this);
        }
        HandlerThread handlerThread = new HandlerThread(str, 10);
        this.playThread = handlerThread;
        handlerThread.start();
        this.workHandler = new Handler(this.playThread.getLooper(), this);
    }

    public void monitor(boolean z, int i, int i2, String str) {
        String str2;
        IMonitor iMonitor = this.monitor;
        if (iMonitor != null) {
            IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer = this.mediaPlayer;
            if (iMediaPlayer != null) {
                str2 = iMediaPlayer.getPlayerSimpleName();
            } else {
                str2 = "unknown";
            }
            boolean z2 = z;
            iMonitor.monitor(z2, str2, i, i2, str + ", messageId: " + this.messageId);
        }
    }

    public PlayerController(Context context2, 0CH r4, IMediaPlayer<AbsPlayer<AbsPlayer>> iMediaPlayer, int i, String str) {
        init(context2, r4, str);
        initAlphaView(i);
        initPlayer(iMediaPlayer);
    }
}
