package com.he.lynx.player;

import android.media.MediaPlayer;
import android.os.Build;
import android.view.Surface;
import com.bytedance.covode.number.Covode;
import com.he.lynx.player.IHeliumPlayer;

public class HeliumPlayerImpl implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, MediaPlayer.OnInfoListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnSeekCompleteListener, IHeliumPlayer {
    public IHeliumPlayer.IHeliumPlayerListener listener = null;
    public MediaPlayer player = new MediaPlayer();

    static {
        Covode.recordClassIndex(45659);
    }

    public int getCurrentPosition() {
        return this.player.getCurrentPosition();
    }

    public int getDuration() {
        return this.player.getDuration();
    }

    public int getVideoHeight() {
        return this.player.getVideoHeight();
    }

    public int getVideoWidth() {
        return this.player.getVideoWidth();
    }

    public boolean isPlaying() {
        return this.player.isPlaying();
    }

    public void pause() {
        this.player.pause();
    }

    public void play() {
        this.player.start();
    }

    public void prepare() {
        this.player.prepareAsync();
    }

    public void release() {
        this.player.release();
    }

    public void stop() {
        this.player.stop();
    }

    public void onCompletion(MediaPlayer mediaPlayer) {
        IHeliumPlayer.IHeliumPlayerListener iHeliumPlayerListener = this.listener;
        if (iHeliumPlayerListener != null) {
            iHeliumPlayerListener.onCompletion(this);
        }
    }

    public void onPrepared(MediaPlayer mediaPlayer) {
        IHeliumPlayer.IHeliumPlayerListener iHeliumPlayerListener = this.listener;
        if (iHeliumPlayerListener != null) {
            iHeliumPlayerListener.onPrepared(this);
        }
    }

    public void onSeekComplete(MediaPlayer mediaPlayer) {
        IHeliumPlayer.IHeliumPlayerListener iHeliumPlayerListener = this.listener;
        if (iHeliumPlayerListener != null) {
            iHeliumPlayerListener.onSeekComplete(this);
        }
    }

    public void setDataSource(String str) {
        this.player.setDataSource(str);
    }

    public void setLooping(boolean z) {
        this.player.setLooping(z);
    }

    public void setSurface(Surface surface) {
        this.player.setSurface(surface);
    }

    public void seekTo(int i) {
        if (Build.VERSION.SDK_INT >= 26) {
            this.player.seekTo((long) i, 3);
        } else {
            this.player.seekTo(i);
        }
    }

    public void setListener(IHeliumPlayer.IHeliumPlayerListener iHeliumPlayerListener) {
        if (iHeliumPlayerListener == null) {
            this.player.setOnPreparedListener((MediaPlayer.OnPreparedListener) null);
            this.player.setOnCompletionListener((MediaPlayer.OnCompletionListener) null);
            this.player.setOnErrorListener((MediaPlayer.OnErrorListener) null);
            this.player.setOnInfoListener((MediaPlayer.OnInfoListener) null);
            this.player.setOnSeekCompleteListener((MediaPlayer.OnSeekCompleteListener) null);
        } else {
            this.player.setOnPreparedListener(this);
            this.player.setOnCompletionListener(this);
            this.player.setOnErrorListener(this);
            this.player.setOnInfoListener(this);
            this.player.setOnSeekCompleteListener(this);
        }
        this.listener = iHeliumPlayerListener;
    }

    public void setVolume(float f, float f2) {
        this.player.setVolume(f, f2);
    }

    public boolean onInfo(MediaPlayer mediaPlayer, int i, int i2) {
        if (i != 3) {
            return false;
        }
        IHeliumPlayer.IHeliumPlayerListener iHeliumPlayerListener = this.listener;
        if (iHeliumPlayerListener == null) {
            return true;
        }
        iHeliumPlayerListener.onRenderStart(this);
        return true;
    }

    public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
        IHeliumPlayer.IHeliumPlayerListener iHeliumPlayerListener = this.listener;
        if (iHeliumPlayerListener == null) {
            return false;
        }
        return iHeliumPlayerListener.onError(this, new Error("what: " + i + ", extra: " + i2));
    }
}
