| | |
| | | |
| | | import androidx.annotation.NonNull; |
| | | |
| | | import com.android.app_base.base.BaseConfig; |
| | | import com.android.app_base.base.view.BaseFragment; |
| | | import com.android.app_base.utils.GlideUtil; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.bean.BannerBean; |
| | | import com.application.zhangshi_app_android.databinding.FragmentVideoBinding; |
| | | import com.shuyu.gsyvideoplayer.GSYVideoManager; |
| | | import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder; |
| | |
| | | */ |
| | | public class VideoFragment extends BaseFragment<FragmentVideoBinding, VideoFragmentViewModel> { |
| | | OrientationUtils orientationUtils; |
| | | private List<String> videoList; |
| | | private boolean isPlay; |
| | | private boolean isPause; |
| | | |
| | | private VideoFragment() { |
| | | private boolean isNeedStart = true;//是否需要开始播放 |
| | | private String playUrl; |
| | | private onPlayListener onPlayListener; |
| | | public VideoFragment() { |
| | | } |
| | | |
| | | public static VideoFragment newInstance() { |
| | | public static VideoFragment newInstance(String url) { |
| | | VideoFragment fragment = new VideoFragment(); |
| | | if (url.contains("profile/upload")) {//如果是上传到服务器的图片 |
| | | //只取profile/upload以后的部分 |
| | | url = url.substring(url.indexOf("profile/upload")); |
| | | url = BaseConfig.BASE_URL_DOMAIN + "/" + url; |
| | | } |
| | | Bundle args = new Bundle(); |
| | | args.putSerializable("playUrl", url); |
| | | fragment.setArguments(args); |
| | | return fragment; |
| | | } |
| | |
| | | @Override |
| | | protected void initParam() { |
| | | if (getArguments() != null) { |
| | | videoList = (List<String>) getArguments().getSerializable("videoList"); |
| | | playUrl = (String) getArguments().getSerializable("playUrl"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | protected void initView() { |
| | | if (videoList != null && videoList.size() > 0){ |
| | | binding.videoPlayer.setVisibility(View.VISIBLE); |
| | | binding.layoutDataNull.setVisibility(View.GONE); |
| | | //增加封面 |
| | | ImageView imageView = new ImageView(getSelfActivity()); |
| | | imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); |
| | | GlideUtil.loadVideoCover(videoList.get(0), imageView,-1,1); |
| | | //增加title |
| | | binding.videoPlayer.getTitleTextView().setVisibility(View.GONE); |
| | | binding.videoPlayer.getBackButton().setVisibility(View.GONE); |
| | | |
| | | if (playUrl != null){ |
| | | //外部辅助的旋转,帮助全屏 |
| | | //orientationUtils = new OrientationUtils(this, binding.videoPlayer); |
| | | //初始化不打开外部的旋转 |
| | | // orientationUtils.setEnable(false); |
| | | |
| | | //增加封面 |
| | | ImageView imageView = new ImageView(getSelfActivity()); |
| | | imageView.setScaleType(ImageView.ScaleType.CENTER); |
| | | GlideUtil.loadVideoCover(playUrl, imageView,-1,1); |
| | | //增加title |
| | | binding.videoPlayer.getTitleTextView().setVisibility(View.GONE); |
| | | binding.videoPlayer.getBackButton().setVisibility(View.GONE); |
| | | GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder(); |
| | | gsyVideoOption.setThumbImageView(imageView) |
| | | .setIsTouchWiget(true) |
| | |
| | | .setLockLand(false) |
| | | .setAutoFullWithSize(false) |
| | | .setShowFullAnimation(false) |
| | | .setUrl(videoList.get(0)) |
| | | .setUrl(playUrl) |
| | | .setNeedLockFull(true) |
| | | .setCacheWithPlay(false) |
| | | .setCacheWithPlay(true) |
| | | .setVideoTitle("") |
| | | .setLooping(true) |
| | | .setLooping(false) |
| | | ///不需要旋转 |
| | | .setNeedOrientationUtils(false) |
| | | .setVideoAllCallBack(new GSYSampleCallBack() { |
| | |
| | | // if (orientationUtils != null) { |
| | | // orientationUtils.backToProtVideo(); |
| | | // } |
| | | } |
| | | |
| | | @Override |
| | | public void onAutoComplete(String url, Object... objects) { |
| | | super.onAutoComplete(url, objects); |
| | | if (onPlayListener != null){ |
| | | onPlayListener.onComplete(); |
| | | } |
| | | isNeedStart = true; |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete(String url, Object... objects) { |
| | | super.onComplete(url, objects); |
| | | // isNeedStart = true; |
| | | } |
| | | }) |
| | | .setLockClickListener(new LockClickListener() { |
| | |
| | | binding.videoPlayer.startWindowFullscreen(getSelfActivity(), true, true); |
| | | } |
| | | }); |
| | | }else { |
| | | binding.videoPlayer.setVisibility(View.GONE); |
| | | binding.layoutDataNull.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | public void setVideoList(List<String> videoList) { |
| | | this.videoList = videoList; |
| | | Bundle args = new Bundle(); |
| | | args.putSerializable("videoList", (Serializable) videoList); |
| | | setArguments(args); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | protected void initLiveDataObserve() { |
| | |
| | | binding.videoPlayer.getCurrentPlayer().onVideoPause(); |
| | | super.onPause(); |
| | | isPause = true; |
| | | System.out.println("onPause"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onResume() { |
| | | binding.videoPlayer.getCurrentPlayer().onVideoResume(false); |
| | | if (isNeedStart){ |
| | | binding.videoPlayer.getCurrentPlayer().startPlayLogic(); |
| | | isNeedStart = false; |
| | | }else { |
| | | binding.videoPlayer.getCurrentPlayer().onVideoResume(false); |
| | | } |
| | | super.onResume(); |
| | | isPause = false; |
| | | } |
| | |
| | | // binding.videoPlayer.onConfigurationChanged(this, newConfig, orientationUtils, true, true); |
| | | // } |
| | | } |
| | | |
| | | public void setOnPlayListener(onPlayListener listener){ |
| | | this.onPlayListener = listener; |
| | | } |
| | | public void startPlay(){ |
| | | isNeedStart = true; |
| | | } |
| | | |
| | | public interface onPlayListener{ |
| | | void onComplete(); |
| | | } |
| | | } |