//package com.hc.lib.video;
//
//import android.content.Context;
//import android.media.MediaPlayer;
//import android.util.AttributeSet;
//import android.view.KeyEvent;
//import android.view.View;
//import android.view.ViewGroup;
//
//import com.hc.lib.R;
//import com.orhanobut.logger.Logger;
//import com.shuyu.gsyvideoplayer.listener.GSYVideoProgressListener;
//import com.shuyu.gsyvideoplayer.utils.CommonUtil;
//import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
//import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
//import com.shuyu.gsyvideoplayer.video.base.GSYVideoPlayer;
//@Deprecated
//public class HCVideoPlayer extends StandardGSYVideoPlayer implements IVideoPlayer, GSYVideoProgressListener {
//
//    //    private VolumeDialogDismissRunnable volumeDialogDismissRunnable;
//    private VideoProgressChangedRunnable videoProgressChangedRunnable;
//    private VideoHideControlViewRunnable videoHideControlViewRunnable;
//
//    private OnPlayerPausedListener onPlayerPausedListener;
//
//    private View payNotice;
//
//    private boolean isChangingProgress = false;
//    private boolean isShowUI = false;
//    private long limitTime = PLAY_TIME_NO_LIMIT;
//
//    private String videoUrl;
//    private boolean cacheWithPlay;
//    private String title;
//    private boolean isLooping;
//    private boolean showCompleteDialog;
//
//    @Override
//    public int getLayoutId() {
//        return R.layout.layout_hc_player;
//    }
//
//    public HCVideoPlayer(Context context) {
//        this(context, null);
//    }
//
//    public HCVideoPlayer(Context context, AttributeSet attrs) {
//        super(context, attrs);
//        mDismissControlTime = 2000;
//        setGSYVideoProgressListener(this);
//
//        payNotice = findViewById(R.id.pay_notice);
//        payNotice.setVisibility(GONE);
//    }
//
//    public void setOnPlayerPausedListener(OnPlayerPausedListener onPlayerPausedListener) {
//        this.onPlayerPausedListener = onPlayerPausedListener;
//    }
//
//    @Override
//    public void setLoop(boolean looping) {
//        this.isLooping = looping;
//    }
//
//    @Override
//    public void setShowCompleteDialog(boolean showCompleteDialog) {
//        this.showCompleteDialog = showCompleteDialog;
//    }
//
//    @Override
//    public boolean setUp(String url, final boolean cacheWithPlay, final String title) {
//        this.videoUrl = url;
//        this.cacheWithPlay = cacheWithPlay;
//        this.title = title;
//        this.setVideoAllCallBack(new VideoCallback() {
//
//            @Override
//            public void onStartPrepared(String url, Object... objects) {
//                super.onStartPrepared(url, objects);
//                if (!isChangingProgress) {
//                    setViewShowState(mLoadingProgressBar, VISIBLE);
//                }
//            }
//
//            @Override
//            public void onPrepared(String url, Object... objects) {
//                super.onPrepared(url, objects);
//                setViewShowState(mLoadingProgressBar, GONE);
//            }
//
//            @Override
//            public void onAutoComplete(String url, Object... objects) {
//                super.onAutoComplete(url, objects);
//                if (isLooping) {
//                    HCVideoPlayer.super.setUp(videoUrl, cacheWithPlay, title);
//                    startPlayLogic();
//                } else if (isShowUI && onPlayerPausedListener != null) {
//                    if (showCompleteDialog) {
//                        onPlayerPausedListener.videoCompleted();
//                    } else {
//                        onVideoDestroy();
//                        onPlayerPausedListener.videoToNext();
//                    }
//                }
//            }
//        });
//        return super.setUp(url, cacheWithPlay, title);
//    }
//
//    @Override
//    public void setFullVideo(boolean fullVideo) {
//        isShowUI = fullVideo;
//    }
//
//    @Override
//    public void setLimitTime(long limitTime) {
//        this.limitTime = limitTime;
//    }
//
//    @Override
//    protected void resolveNormalVideoShow(View oldF, ViewGroup vp, GSYVideoPlayer gsyVideoPlayer) {
//        super.resolveNormalVideoShow(oldF, vp, gsyVideoPlayer);
//        if (gsyVideoPlayer != null) {
//            GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_FULL);
//            changeTextureViewShowType();
//            if (mTextureView != null)
//                mTextureView.requestLayout();
//        }
//    }
//
//    @Override
//    public void onInfo(int what, int extra) {
//        if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
//            mBackUpPlayingBufferState = mCurrentState;
//            //避免在onPrepared之前就进入了buffering，导致一只loading
//            if (mHadPlay && mCurrentState != CURRENT_STATE_PREPAREING && mCurrentState > 0)
//                setStateAndUi(CURRENT_STATE_PLAYING_BUFFERING_START);
//
//        } else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
//            if (mBackUpPlayingBufferState != -1) {
//                if (mBackUpPlayingBufferState == CURRENT_STATE_PLAYING_BUFFERING_START) {
//                    mBackUpPlayingBufferState = CURRENT_STATE_PLAYING;
//                }
//                if (mHadPlay && mCurrentState != CURRENT_STATE_PREPAREING && mCurrentState > 0)
//                    setStateAndUi(mBackUpPlayingBufferState);
//
//                mBackUpPlayingBufferState = -1;
//            }
//        } else if (what == getGSYVideoManager().getRotateInfoFlag()) {
////            mRotate = extra;//<---------------------这里
//            mRotate = 0;// 修改为0， 使用GSYVideoType.setRenderType(GSYVideoType.SUFRACE)时就不会有黑边
//            Logger.d("Video Rotate Info %s", extra);
//            if (mTextureView != null)
//                mTextureView.setRotation(mRotate);
//        }
//    }
//
//    @Override
//    protected boolean isShowNetConfirm() {
//        return false;
//    }
//
//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        Logger.d("HCVideoPlayer onKeyDown start: %s", keyCode);
//        switch (keyCode) {
//            case KeyEvent.KEYCODE_DPAD_LEFT:
//                if (!isChangingProgress && mCurrentState == CURRENT_STATE_PLAYING) {
//                    mSeekTimePosition = getCurrentPositionWhenPlaying();
//                }
//                isChangingProgress = true;
//                changeProgress(true);
//                return true;
//            case KeyEvent.KEYCODE_DPAD_RIGHT:
//                if (!isChangingProgress && mCurrentState == CURRENT_STATE_PLAYING) {
//                    mSeekTimePosition = getCurrentPositionWhenPlaying();
//                }
//                isChangingProgress = true;
//                changeProgress(false);
//                return true;
//            case KeyEvent.KEYCODE_DPAD_UP:
//                showControlWidget();
////                changeVolume(true);
//                break;
//            case KeyEvent.KEYCODE_DPAD_DOWN:
//                showControlWidget();
////                changeVolume(false);
//                break;
//            case KeyEvent.KEYCODE_DPAD_CENTER:
//                pauseOrPlay(false);
//                break;
//            case KeyEvent.KEYCODE_ENTER:
//                pauseOrPlay(false);
//                break;
//            default:
//                break;
//        }
//        Logger.d("HCVideoPlayer onKeyDown end: %s", keyCode);
//        return super.onKeyDown(keyCode, event);
//    }
//
//    @Override
//    public void pauseOrPlay(boolean play) {
////        if (mCurrentState == CURRENT_STATE_PLAYING) {
////            try {
////                onVideoPause();
////            } catch (Exception e) {
////                e.printStackTrace();
////            }
////            if (onPlayerPausedListener != null) { // 暂停状态显示弹窗
////                onPlayerPausedListener.videoPaused();
////            }
////        } else {
////            try {
////                getGSYVideoManager().start();
////            } catch (Exception e) {
////                e.printStackTrace();
////            }
////        }
//        if (mCurrentState == CURRENT_STATE_PLAYING && play) { //已是播放状态，忽略
//            return;
//        }
//        getStartButton().performClick();
//        if (mCurrentState != CURRENT_STATE_PLAYING && !play && onPlayerPausedListener != null) { // 非播放状态显示弹窗
//            onPlayerPausedListener.videoPaused();
//        }
//    }
//
//    public boolean isCompleted() {
//        return mCurrentState == CURRENT_STATE_AUTO_COMPLETE;
//    }
//
//    /**
//     * 隐藏所有UI
//     */
//    @Override
//    public void hideAllWidget() {
//        changeUiToClear();
//    }
//
//    /**
//     * 显示控制器
//     */
//    private void showControlWidget() {
//        if(isChangingProgress) {
//            return;
//        }
//        changeUiToPlayingShow();
//
//        if (videoHideControlViewRunnable == null) {
//            videoHideControlViewRunnable = new VideoHideControlViewRunnable(this);
//        }
//        getRootView().getHandler().removeCallbacks(videoHideControlViewRunnable);
//        getRootView().getHandler().postDelayed(videoHideControlViewRunnable, 3000);
//    }
//
//    /**
//     * 更改播放进度
//     *
//     * @param back 是否回退，false为跨快进
//     */
//    private void changeProgress(boolean back) {
//
//        changeUiToPlayingShow();
//        cancelProgressTimer();
//
//        onVideoPause();
//
//        int seekTimePos = mSeekTimePosition;
//        int totalTimeDuration = getDuration();
//        if (back) {
//            seekTimePos -= TIME; // 快退10s
//            if (seekTimePos < 0) {
//                seekTimePos = 1;
//            }
//        } else {
//            seekTimePos += TIME; // 快进10s
//            if (seekTimePos > totalTimeDuration) {
//                seekTimePos = totalTimeDuration - 1;
//            }
//        }
//        String seekTime = CommonUtil.stringForTime(seekTimePos);
//        int progress = seekTimePos * 100 / totalTimeDuration;
//        mCurrentTimeTextView.setText(seekTime);
//        if (progress >= 0) mProgressBar.setProgress(progress);
//
//        mSeekTimePosition = seekTimePos;
//
//        changedProgressFinished(seekTimePos);
//
//        if (videoProgressChangedRunnable == null) {
//            videoProgressChangedRunnable = new VideoProgressChangedRunnable(this);
//        }
//        videoProgressChangedRunnable.setSeekPosition(seekTimePos);
//        getRootView().getHandler().removeCallbacks(videoProgressChangedRunnable);
//        getRootView().getHandler().postDelayed(videoProgressChangedRunnable, 500);
//    }
//
//    @Override
//    protected void setTextAndProgress(int secProgress) {
//        if (isChangingProgress) {
//            int position = mSeekTimePosition;
//            int duration = getDuration();
//            int progress = position * 100 / (duration == 0 ? 1 : duration);
//            setProgressAndTime(progress, secProgress, position, duration);
//        } else {
//            super.setTextAndProgress(secProgress);
//        }
//    }
//
//    @Override
//    protected void cancelProgressTimer() {
//        super.cancelProgressTimer();
//    }
//
//    /**
//     * 快进快退操作完成，执行视频进度跳转逻辑
//     */
//    private void changedProgressFinished(final int seekPosition) {
//        if (getGSYVideoManager() != null) {
//            try {
//                getGSYVideoManager().seekTo(seekPosition);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//    }
//
//    private void finishedProgressAndStart(int seekPosition) {
//        changedProgressFinished(seekPosition);
//        try {
//            getGSYVideoManager().start();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    @Override
//    public void onProgress(int progress, int secProgress, int currentPosition, int duration) {
//        if (limitTime == PLAY_TIME_NO_LIMIT) {
//            return;
//        }
//        if (currentPosition >= limitTime) {
//            onVideoPause();
//            // 跳转订购
//            onPlayerPausedListener.videoExit();
//        }
//    }
//
////    /**
////     * 声音对话框消失线程
////     */
////    private static class VolumeDialogDismissRunnable implements Runnable {
////
////        private HCVideoPlayer videoPlayer;
////
////        VolumeDialogDismissRunnable(HCVideoPlayer videoPlayer) {
////            this.videoPlayer = videoPlayer;
////        }
////
////        @Override
////        public void run() {
////            videoPlayer.dismissVolumeDialog();
////        }
////    }
//
//    /**
//     * 视频进度对话框消失线程
//     */
//    private static class VideoProgressChangedRunnable implements Runnable {
//
//        private HCVideoPlayer videoPlayer;
//        private int seekPosition = 0;
//
//        VideoProgressChangedRunnable(HCVideoPlayer videoPlayer) {
//            this.videoPlayer = videoPlayer;
//        }
//
//        public void setSeekPosition(int seekPosition) {
//            this.seekPosition = seekPosition;
//        }
//
//        @Override
//        public void run() {
//            videoPlayer.finishedProgressAndStart(seekPosition);
//            videoPlayer.showControlWidget();
//            videoPlayer.isChangingProgress = false;
//        }
//    }
//
//    /**
//     * 视频控制视图消失线程
//     */
//    private static class VideoHideControlViewRunnable implements Runnable {
//
//        private HCVideoPlayer videoPlayer;
//
//        VideoHideControlViewRunnable(HCVideoPlayer videoPlayer) {
//            this.videoPlayer = videoPlayer;
//        }
//
//        @Override
//        public void run() {
//            videoPlayer.startDismissControlViewTimer();
//            videoPlayer.startProgressTimer();
//            videoPlayer.isChangingProgress = false;
//        }
//    }
//
//    @Override
//    public void onVideoDestroy() {
//        if (videoProgressChangedRunnable != null) {
//            getRootView().getHandler().removeCallbacks(videoProgressChangedRunnable);
//        }
////        if (volumeDialogDismissRunnable != null) {
////            getRootView().getHandler().removeCallbacks(volumeDialogDismissRunnable);
////        }
//        if (videoHideControlViewRunnable != null) {
//            getRootView().getHandler().removeCallbacks(videoHideControlViewRunnable);
//        }
//        clearCurrentCache();
//        setVideoAllCallBack(null);
//
//        isChangingProgress = false;
//        isShowUI = false;
//        limitTime = PLAY_TIME_NO_LIMIT;
//    }
//
//    @Override
//    protected void changeUiToNormal() {
////        Logger.d("changeUiToNormal");
//        if (isShowUI) {
//            super.changeUiToNormal();
//        }
//    }
//
//    @Override
//    protected void changeUiToPreparingShow() {
////        Logger.d("changeUiToPreparingShow");
//        setViewShowState(mLoadingProgressBar, VISIBLE);
//        setViewShowState(mTopContainer, isShowUI ? VISIBLE : INVISIBLE);
//        setViewShowState(mBottomContainer, isShowUI ? VISIBLE : INVISIBLE);
//        setViewShowState(mThumbImageViewLayout, isShowUI ? VISIBLE : INVISIBLE);
//        setViewShowState(mBottomProgressBar, isShowUI ? VISIBLE : INVISIBLE);
//    }
//
//    @Override
//    protected void changeUiToPlayingShow() {
////        Logger.d("changeUiToPlayingShow");
//        if (isShowUI) {
//            super.changeUiToPlayingShow();
//        }
//    }
//
//    @Override
//    protected void changeUiToPauseShow() {
////        Logger.d("changeUiToPauseShow");
//        if (isShowUI) {
//            super.changeUiToPauseShow();
//        }
//    }
//
//    @Override
//    protected void changeUiToPlayingBufferingShow() {
////        Logger.d("changeUiToPlayingBufferingShow");
//        setViewShowState(mTopContainer, isShowUI ? VISIBLE : INVISIBLE);
//        setViewShowState(mBottomContainer, isShowUI ? VISIBLE : INVISIBLE);
//        setViewShowState(mLoadingProgressBar, VISIBLE);
//        setViewShowState(mThumbImageViewLayout, isShowUI ? VISIBLE : INVISIBLE);
//        setViewShowState(mBottomProgressBar, isShowUI ? VISIBLE : INVISIBLE);
//    }
//
//    @Override
//    protected void changeUiToCompleteShow() {
////        Logger.d("changeUiToCompleteShow");
//        if (isShowUI) {
//            super.changeUiToCompleteShow();
//        }
//    }
//
//    @Override
//    protected void changeUiToError() {
////        Logger.d("changeUiToError");
//        super.changeUiToError();
//    }
//}
