package com.bokecc.livemodule.replaymix.video;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.bokecc.dwlivedemo.R;
import com.bokecc.livemodule.replaymix.DWReplayMixCoreHandler;
import com.bokecc.livemodule.replaymix.DWReplayMixVideoListener;
import com.bokecc.livemodule.view.VideoLoadingView;
import com.bokecc.sdk.mobile.live.stream.live.rtc.HDMediaView;


/**
 * CC 回放视频展示控件
 */
public class ReplayMixVideoView extends RelativeLayout implements DWReplayMixVideoListener {

    Context mContext;

    View mRootView;


    VideoLoadingView mVideoProgressBar;
    private FrameLayout videoRoot;
    public ReplayMixVideoView(Context context) {
        super(context);
        this.mContext = context;
        inflateViews();
    }

    public ReplayMixVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        inflateViews();
    }

    public ReplayMixVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        inflateViews();
    }

    private void inflateViews() {
        mRootView = LayoutInflater.from(mContext).inflate(R.layout.replay_video_view, this);
        videoRoot = mRootView.findViewById(R.id.video_root);
        mVideoProgressBar = mRootView.findViewById(R.id.video_progressBar);
        DWReplayMixCoreHandler.getInstance().setDwReplayMixVideoListener(this);
    }

    @Override
    public void onPlayBackStreamViewPrepared(HDMediaView hdMediaView) {
        if (videoRoot!=null){
            if (videoRoot.getChildCount()>0){
                videoRoot.removeAllViews();
            }
            videoRoot.addView(hdMediaView);
        }
    }

    @Override
    public void onPlayerPrepared() {
        mVideoProgressBar.setVisibility(VISIBLE);
    }

    @Override
    public void onBufferStart() {
        mVideoProgressBar.setVisibility(VISIBLE);
    }

    @Override
    public void onBufferEnd() {
        mVideoProgressBar.setVisibility(GONE);
    }

    @Override
    public void onRenderStart() {
        mVideoProgressBar.setVisibility(GONE);
    }
}
