package com.xty.base.act

import android.view.View
import android.widget.ImageView
import com.alibaba.android.arouter.facade.annotation.Route
import com.shuyu.gsyvideoplayer.GSYVideoManager
import com.shuyu.gsyvideoplayer.player.PlayerFactory
import com.xty.base.databinding.ActVideoPalyBinding
import com.xty.common.arouter.ARouterUrl
import com.xty.common.getThumbVideo
import com.xty.common.picture.PictureUtils
import tv.danmaku.ijk.media.exo2.Exo2PlayerManager


/**
 * 视频播放
 */
@Route(path = ARouterUrl.VIDEO_PLAY)
class VideoPlayerAct: IBaseAct() {
    val binding by lazy{ActVideoPalyBinding.inflate(layoutInflater)}
    var url=""
    var isLocalFile=false
    override fun initData() {
        super.initData()
        intent.extras?.let {
            url=it.getString("video").toString()
            isLocalFile=it.getBoolean("local")
        }



    }

    override fun setLayout()=binding.root
    override fun initView() {

        PlayerFactory.setPlayManager(Exo2PlayerManager::class.java)
        binding.mGsy.setUp(url,false,"")
        binding.mGsy.thumbImageViewLayout.visibility=View.VISIBLE

        var view=ImageView(this)
        when(isLocalFile){
            false-> view.getThumbVideo(this,url)
            true -> PictureUtils.getVideoThumb(url,view)
        }
        binding.mGsy.thumbImageView=view
        binding.mGsy.fullscreenButton.visibility=View.GONE
        binding.mGsy.setIsTouchWiget(true)
        binding.mGsy.backButton.setOnClickListener {
            finish()
        }
    }

    override fun onPause() {
        super.onPause()
        GSYVideoManager.onPause();
    }

    override fun onDestroy() {
        super.onDestroy()
        GSYVideoManager.releaseAllVideos()
    }
}