diff --git a/app/src/main/java/com/gh/download/cache/ExoCacheManager.kt b/app/src/main/java/com/gh/download/cache/ExoCacheManager.kt index e769c906c6..b3fe543a68 100644 --- a/app/src/main/java/com/gh/download/cache/ExoCacheManager.kt +++ b/app/src/main/java/com/gh/download/cache/ExoCacheManager.kt @@ -23,11 +23,14 @@ import java.util.concurrent.atomic.AtomicBoolean object ExoCacheManager { private val threads = ConcurrentHashMap() + private const val preLength = 50 * 1024 * 1024L //预加载视频大小 fun preload(videoUri: String) { runOnIoThread { threads[videoUri] = AtomicBoolean(false) - val dataSpec = DataSpec(Uri.parse(videoUri), 0, getContentLength(videoUri), null) + val contentLength = getContentLength(videoUri) + val cacheLength = if (contentLength >= preLength) preLength else contentLength + val dataSpec = DataSpec(Uri.parse(videoUri), 0, cacheLength, null) val simpleCache = ExoSourceManager.getCacheSingleInstance(HaloApp.getInstance().application, null) val dataSourceFactory = GSYExoHttpDataSourceFactory(Util.getUserAgent(HaloApp.getInstance().application, "ExoCacheManager"), DefaultBandwidthMeter.Builder(HaloApp.getInstance().application).build(), diff --git a/app/src/main/java/com/gh/gamecenter/video/detail/CustomManager.java b/app/src/main/java/com/gh/gamecenter/video/detail/CustomManager.java index 456a0529d6..51118c2730 100644 --- a/app/src/main/java/com/gh/gamecenter/video/detail/CustomManager.java +++ b/app/src/main/java/com/gh/gamecenter/video/detail/CustomManager.java @@ -39,9 +39,9 @@ public class CustomManager extends GSYVideoBaseManager { private static Map sMap = new HashMap<>(); - private static final int DEFAULT_MIN_BUFFER_MS = 5000; + private static final int DEFAULT_MIN_BUFFER_MS = 10 * 1000; - private static final int DEFAULT_MAX_BUFFER_MS = 20000; + private static final int DEFAULT_MAX_BUFFER_MS = 20 * 1000; public CustomManager() { diff --git a/app/src/main/java/com/gh/gamecenter/video/detail/DetailPlayerView.kt b/app/src/main/java/com/gh/gamecenter/video/detail/DetailPlayerView.kt index abea0755f4..a86fd5c32a 100644 --- a/app/src/main/java/com/gh/gamecenter/video/detail/DetailPlayerView.kt +++ b/app/src/main/java/com/gh/gamecenter/video/detail/DetailPlayerView.kt @@ -21,6 +21,7 @@ import com.gh.common.constant.Constants import com.gh.common.observer.MuteCallback import com.gh.common.observer.VolumeObserver import com.gh.common.runOnIoThread +import com.gh.common.runOnUiThread import com.gh.common.util.* import com.gh.download.cache.CacheManager import com.gh.gamecenter.GameDetailActivity @@ -778,9 +779,12 @@ class DetailPlayerView @JvmOverloads constructor(context: Context, attrs: Attrib if (mContentLength == 0.0) { mContentLength = CacheManager.getInstance().getContentLength(mVideoEntity!!.url) / 1024.0 / 1024.0 } - LogUtils.uploadVideoStreamingPlaying(action, msg, mViewModel!!.path, - mViewModel!!.entranceDetail, mVideoEntity!!.id, mViewModel!!.uuid, mContentLength, - duration / 1000, currentPositionWhenPlaying / 1000, videoPlayStatus()) + //https://exoplayer.dev/hello-world.html#a-note-on-threading + runOnUiThread { + LogUtils.uploadVideoStreamingPlaying(action, msg, mViewModel!!.path, + mViewModel!!.entranceDetail, mVideoEntity!!.id, mViewModel!!.uuid, mContentLength, + duration / 1000, currentPositionWhenPlaying / 1000, videoPlayStatus()) + } } }