package com.xunao.effectdemo.activity;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.xunao.effectdemo.R;
import com.xunao.effectdemo.view.VideoPreviewPlay;

/**
 * author : 程中强
 * e-mail : 740479946@qq.com
 * date : 2022/9/1417:18
 * desc :
 * version: 1.0
 */
public class GSXYVideoPlayerActivity extends Activity {

	VideoPreviewPlay videoPlayer;
	private OrientationUtils orientationUtils;
	private Button btn;
	private boolean isFirst = false;
	private String url = "http://v3.cztv.com/cztv/vod/2018/06/28/7c45987529ea410dad7c088ba3b53dac/h264_1500k_mp4.mp4";
	@Override
	protected void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gsxy_video);
		init();
	}

	void init(){
		videoPlayer = findViewById(R.id.video_play);
		videoPlayer.setUp(url, true, "null");


		//增加title
		videoPlayer.getTitleTextView().setVisibility(View.GONE);
		//设置返回键
		videoPlayer.getBackButton().setOnClickListener(v->{
			finish();
		});
		videoPlayer.getFullscreenButton().setVisibility(View.GONE);
		orientationUtils = new OrientationUtils(this, videoPlayer);
		videoPlayer.setIsFinish(isFirst);
		videoPlayer.setIsTouchWiget(isFirst);
		videoPlayer.setIsTouchWigetFull(isFirst);
		videoPlayer.setIfCurrentIsFullscreen(false);
		videoPlayer.startPlayLogic();

		btn = findViewById(R.id.btn_finish);
		btn.setOnClickListener(v->{
			isFirst = !isFirst;
			videoPlayer.setIsFinish(isFirst);
//			videoPlayer.setIsTouchWiget(isFirst);
//			videoPlayer.setIsTouchWigetFull(isFirst);
		});
	}

	@Override
	protected void onResume() {
		super.onResume();
		videoPlayer.onVideoResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
		videoPlayer.onVideoPause();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		GSYVideoManager.releaseAllVideos();
		if (orientationUtils != null)
			orientationUtils.releaseListener();
	}

//	@Override
//	public void onBackPressed() {
//		//先返回正常状态
//		if (orientationUtils.getScreenType() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
//			videoPlayer.getFullscreenButton().performClick();
//			return;
//		}
//		//释放所有
//		videoPlayer.setVideoAllCallBack(null);
//		super.onBackPressed();
//	}
}
