From 63608b5dca9eebb6fa2cb1a8652b395f1d910c3e Mon Sep 17 00:00:00 2001 From: 张钢 <floatgang@163.com> Date: 星期一, 02 九月 2024 13:52:17 +0800 Subject: [PATCH] 对新接口进行了适配 --- app/src/main/java/com/application/zhangshi_app_android/ui/function/VideoFragment.java | 79 +++++++++++++++++++++++---------------- 1 files changed, 47 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/VideoFragment.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/VideoFragment.java index 13ca480..57d27e1 100644 --- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/VideoFragment.java +++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/VideoFragment.java @@ -8,6 +8,7 @@ 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; @@ -30,16 +31,23 @@ */ public class VideoFragment extends BaseFragment<FragmentVideoBinding, VideoFragmentViewModel> { OrientationUtils orientationUtils; - private List<BannerBean> videoList; private boolean isPlay; private boolean isPause; - + 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; } @@ -59,24 +67,13 @@ @Override protected void initParam() { if (getArguments() != null) { - videoList = (List<BannerBean>) getArguments().getSerializable("videoList"); + playUrl = (String) getArguments().getSerializable("playUrl"); } } @Override protected void initView() { - String playUrl = null; - for (BannerBean bannerBean : videoList) { - if (bannerBean.getChoose() == 1){ - playUrl = bannerBean.getUrl(); - break; - } - } if (playUrl != null){ - binding.videoPlayer.setVisibility(View.VISIBLE); - binding.layoutDataNull.setVisibility(View.GONE); - - //澶栭儴杈呭姪鐨勬棆杞紝甯姪鍏ㄥ睆 //orientationUtils = new OrientationUtils(this, binding.videoPlayer); //鍒濆鍖栦笉鎵撳紑澶栭儴鐨勬棆杞� @@ -98,7 +95,7 @@ .setShowFullAnimation(false) .setUrl(playUrl) .setNeedLockFull(true) - .setCacheWithPlay(false) + .setCacheWithPlay(true) .setVideoTitle("") .setLooping(false) ///涓嶉渶瑕佹棆杞� @@ -120,6 +117,21 @@ // 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() { @@ -143,9 +155,6 @@ binding.videoPlayer.startWindowFullscreen(getSelfActivity(), true, true); } }); - }else { - binding.videoPlayer.setVisibility(View.GONE); - binding.layoutDataNull.setVisibility(View.VISIBLE); } } @@ -154,19 +163,7 @@ } - public void setVideoList(List<BannerBean> videoList) { - this.videoList = videoList; - Bundle args = new Bundle(); - args.putSerializable("videoList", (Serializable) videoList); - setArguments(args); - if (isAdded()){ - initView(); - } - } - public List<BannerBean> getVideoList() { - return videoList; - } @Override protected void initLiveDataObserve() { @@ -192,11 +189,18 @@ 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; } @@ -223,4 +227,15 @@ // 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(); + } } -- Gitblit v1.9.1