diff --git a/app/src/main/java/com/gh/download/cache/CacheManager.java b/app/src/main/java/com/gh/download/cache/CacheManager.java index a539e4cd37..7ac00741ea 100644 --- a/app/src/main/java/com/gh/download/cache/CacheManager.java +++ b/app/src/main/java/com/gh/download/cache/CacheManager.java @@ -2,6 +2,7 @@ package com.gh.download.cache; import com.danikula.videocache.file.FileNameGenerator; import com.danikula.videocache.file.Md5FileNameGenerator; +import com.gh.common.AppExecutor; import com.halo.assistant.HaloApp; import com.shuyu.gsyvideoplayer.utils.StorageUtils; @@ -34,7 +35,7 @@ public class CacheManager { private File cacheDirectory = StorageUtils.getIndividualCacheDirectory(HaloApp.getInstance().getApplication()); private FileNameGenerator generator = new Md5FileNameGenerator(); private final String TEMP_POSTFIX = ".download"; - private final int preLength = 5 * 1024 * 1024;//预加载大小 +// private final int preLength = 5 * 1024 * 1024;//预加载大小 public static CacheManager getInstance() { @@ -130,13 +131,15 @@ public class CacheManager { String url = cacheInfo.getUrl(); final long[] downloadLength = {cacheInfo.getProgress()};//已经下载好的长度 long contentLength = cacheInfo.getTotal();//文件的总长度 - if (downloadLength[0] >= preLength) { +// if (downloadLength[0] >= preLength) { + if (downloadLength[0] >= contentLength) { e.onComplete(); return; } e.onNext(cacheInfo); Request request = new Request.Builder() - .addHeader("RANGE", "bytes=" + downloadLength[0] + "-" + (contentLength > preLength ? preLength : contentLength)) +// .addHeader("RANGE", "bytes=" + downloadLength[0] + "-" + (contentLength > preLength ? preLength : contentLength)) + .addHeader("RANGE", "bytes=" + downloadLength[0] + "-" + contentLength) .url(url) .build(); Call call = mClient.newCall(request); @@ -214,10 +217,12 @@ public class CacheManager { } public void removeAllCall() { - for (Map.Entry entry : getDownCalls().entrySet()) { - entry.getValue().cancel(); - } - getDownCalls().clear(); + AppExecutor.getIoExecutor().execute(() -> { + for (Map.Entry entry : getDownCalls().entrySet()) { + entry.getValue().cancel(); + } + AppExecutor.getUiExecutor().execute(() -> getDownCalls().clear()); + }); } private List getAllFile() { diff --git a/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt b/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt index 6ad5a22e90..acca8ce69e 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/comment/NewCommentFragment.kt @@ -28,9 +28,11 @@ import com.gh.gamecenter.adapter.OnCommentCallBackListener import com.gh.gamecenter.baselist.ListAdapter import com.gh.gamecenter.baselist.ListFragment import com.gh.gamecenter.entity.CommentEntity +import com.gh.gamecenter.eventbus.EBReuse import com.gh.gamecenter.qa.answer.detail.AnswerDetailFragment import com.halo.assistant.HaloApp import com.lightgame.utils.Util_System_Keyboard +import org.greenrobot.eventbus.EventBus open class NewCommentFragment : ListFragment(), OnCommentCallBackListener, KeyboardHeightObserver { @@ -172,11 +174,14 @@ open class NewCommentFragment : ListFragment if (this !is NewCommentConversationFragment) { mKeyboardHeightProvider?.setKeyboardHeightObserver(this) } + + EventBus.getDefault().post(EBReuse(COMMENT_RESUME)) } override fun onPause() { super.onPause() mKeyboardHeightProvider?.setKeyboardHeightObserver(null) + mBaseHandler.postDelayed({EventBus.getDefault().post(EBReuse(COMMENT_PAUSE))},1000) } override fun onDestroy() { @@ -351,6 +356,10 @@ open class NewCommentFragment : ListFragment } companion object { + + const val COMMENT_PAUSE = "comment_pause" + const val COMMENT_RESUME = "comment_resume" + fun getAnswerCommentInstance(answerId: String, showSoftKeyboardOnStartUp: Boolean, commentCount: Int, diff --git a/app/src/main/java/com/gh/gamecenter/video/detail/VideoDetailContainerFragment.kt b/app/src/main/java/com/gh/gamecenter/video/detail/VideoDetailContainerFragment.kt index 940ccd3adb..8fb4aab427 100644 --- a/app/src/main/java/com/gh/gamecenter/video/detail/VideoDetailContainerFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/video/detail/VideoDetailContainerFragment.kt @@ -31,8 +31,11 @@ import com.gh.gamecenter.entity.LinkEntity import com.gh.gamecenter.entity.VideoEntity import com.gh.gamecenter.eventbus.EBDownloadStatus import com.gh.gamecenter.eventbus.EBPackage +import com.gh.gamecenter.eventbus.EBReuse import com.gh.gamecenter.manager.UserManager import com.gh.gamecenter.qa.comment.CommentActivity +import com.gh.gamecenter.qa.comment.NewCommentFragment +import com.halo.assistant.HaloApp import com.lightgame.download.DataWatcher import com.lightgame.download.DownloadEntity import com.lightgame.listeners.OnBackPressedListener @@ -142,6 +145,9 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener { if (!isShowSlide) { showSlideGuide() } + if (mIsHomeVideo) { + setAdvertisement(0) + } } } @@ -184,10 +190,6 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener { mViewModel.needToUpdateVideoInfo.observeNonNull(this) { findFirstCompletelyVisibleVideoViewByPosition()?.updateViewDetail(it) } - - if (mIsHomeVideo) { - setAdvertisement(0) - } } private fun initListener() { @@ -439,7 +441,6 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener { val videoView = findFirstCompletelyVisibleVideoViewByPosition() videoView?.run { if (videoView.isInPlayingState) { -// CustomManager.onResume("detail_${mViewModel.uuid}", false) videoView.onVideoResume(false) } else {//快速切换视频后再切换页面可能没有播放 videoView.startButton?.performClick() @@ -469,7 +470,6 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener { videoView.uploadVideoStreamingPlaying("暂停页面") if (pauseVideo[mViewModel.uuid] == true) { if (videoView.isInPlayingState) { -// CustomManager.onPause("detail_${mViewModel.uuid}") videoView.onVideoPause() } else { CustomManager.releaseAllVideos("detail_${mViewModel.uuid}") @@ -482,7 +482,6 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener { } SPUtils.setBoolean(Constants.SP_SHOW_SLIDE_GUIDE, true) - CacheManager.getInstance().removeAllCall() val proxy = CustomProxyCacheManager.getProxy(requireContext(), null) runOnIoThread { proxy.allClients.forEach { @@ -497,6 +496,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener { serverSocket.close() }*/ super.onPause() + CacheManager.getInstance().removeAllCall() } override fun onDestroyView() { @@ -505,12 +505,12 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener { mBaseHandler.postDelayed({ CustomManager.releaseAllVideos("detail_${mViewModel.uuid}") }, 500) - CacheManager.getInstance().removeAllCall() if (mAdCountDownTimer != null && !mAdCountDownTimer!!.isDisposed) { mAdCountDownTimer?.dispose() } pauseVideo.remove(mViewModel.uuid) super.onDestroyView() + CacheManager.getInstance().removeAllCall() } private fun findFirstCompletelyVisibleVideoViewByPosition(): DetailPlayerView? { @@ -654,6 +654,32 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener { } } + @Subscribe(threadMode = ThreadMode.MAIN) + fun onEventMainThread(status: EBReuse) { + val videoView = findFirstCompletelyVisibleVideoViewByPosition() + //处理打开评论页面,按手机Home键回到桌面,还会听到视频的声音 + if (NewCommentFragment.COMMENT_PAUSE == status.type) { + if (!HaloApp.getInstance().isRunningForeground) { + videoView?.onVideoPause() + } + } + //产品没说回到前台需要继续恢复播放,先注释掉 + /*else if (NewCommentFragment.COMMENT_RESUME == status.type) { + val activityStack = AppManager.getInstance().activityStack + var i = activityStack.size - 1 + while (i >= 0) { + val activity = activityStack[i] + if (activity is VideoDetailActivity || activity is MainActivity) { + if (requireActivity().componentName == activity.componentName) { + videoView?.onVideoResume(false) + } + break + } + i-- + } + }*/ + } + override fun onHandleBackPressed(): Boolean { if (::mAdapter.isInitialized) { return mAdapter.onBackPressed(findFirstCompletelyVisibleVideoViewByPosition()) diff --git a/libraries/gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/HttpUrlSource.java b/libraries/gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/HttpUrlSource.java index a86861792f..79e372e62e 100644 --- a/libraries/gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/HttpUrlSource.java +++ b/libraries/gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/HttpUrlSource.java @@ -98,17 +98,18 @@ public class HttpUrlSource implements Source { if (connection != null) { try { connection.disconnect(); - } catch (NullPointerException | IllegalArgumentException e) { + } catch (Exception e) { String message = "Wait... but why? WTF!? " + "Really shouldn't happen any more after fixing https://github.com/danikula/AndroidVideoCache/issues/43. " + "If you read it on your device log, please, notify me danikula@gmail.com or create issue here " + "https://github.com/danikula/AndroidVideoCache/issues."; - throw new RuntimeException(message, e); - } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); +// throw new RuntimeException(message, e); + } /*catch (ArrayIndexOutOfBoundsException e) { HttpProxyCacheDebuger.printfError("Error closing connection correctly. Should happen only on Android L. " + "If anybody know how to fix it, please visit https://github.com/danikula/AndroidVideoCache/issues/88. " + "Until good solution is not know, just ignore this issue :(", e); - } + }*/ } }