光环助手V4.0-视频相关测试汇总(正式环境)https://gitlab.ghzs.com/pm/halo-app-issues/issues/794

This commit is contained in:
Jack
2020-03-02 18:31:30 +08:00
parent a3d7d9cb81
commit 166f44bb1d
2 changed files with 48 additions and 27 deletions

View File

@ -2,6 +2,7 @@ package com.gh.download.cache
import android.net.Uri
import com.gh.common.runOnIoThread
import com.gh.common.util.NetworkUtils
import com.gh.gamecenter.BuildConfig
import com.google.android.exoplayer2.upstream.DataSpec
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter
@ -26,29 +27,31 @@ object ExoCacheManager {
private const val preLength = 50 * 1024 * 1024L //预加载视频大小
fun preload(videoUri: String) {
runOnIoThread {
threads[videoUri] = AtomicBoolean(false)
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(),
GSYExoHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
GSYExoHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false)
val cacheDataSource = CacheDataSource(simpleCache, dataSourceFactory.createDataSource())
try {
CacheUtil.cache(dataSpec, simpleCache, CacheUtil.DEFAULT_CACHE_KEY_FACTORY, cacheDataSource, CacheUtil.ProgressListener { requestLength, bytesCached, newBytesCached ->
if (requestLength == bytesCached) {
threads.remove(videoUri)
}
if (BuildConfig.DEBUG) {
Utils.log("$requestLength--$bytesCached--$newBytesCached")
}
}, threads[videoUri])
} catch (e: Exception) {
threads.remove(videoUri)
e.printStackTrace()
if (NetworkUtils.isWifiConnected(HaloApp.getInstance().application)) {
runOnIoThread {
threads[videoUri] = AtomicBoolean(false)
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(),
GSYExoHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
GSYExoHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false)
val cacheDataSource = CacheDataSource(simpleCache, dataSourceFactory.createDataSource())
try {
CacheUtil.cache(dataSpec, simpleCache, CacheUtil.DEFAULT_CACHE_KEY_FACTORY, cacheDataSource, CacheUtil.ProgressListener { requestLength, bytesCached, newBytesCached ->
if (requestLength == bytesCached) {
threads.remove(videoUri)
}
if (BuildConfig.DEBUG) {
Utils.log("$requestLength--$bytesCached--$newBytesCached")
}
}, threads[videoUri])
} catch (e: Exception) {
threads.remove(videoUri)
e.printStackTrace()
}
}
}
}

View File

@ -37,6 +37,8 @@ import com.halo.assistant.fragment.SettingsFragment
import com.jakewharton.rxbinding2.view.RxView
import com.lightgame.utils.Utils
import com.shuyu.gsyvideoplayer.listener.VideoAllCallBack
import com.shuyu.gsyvideoplayer.utils.Debuger
import com.shuyu.gsyvideoplayer.utils.NetInfoModule
import com.shuyu.gsyvideoplayer.utils.NetworkUtils
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
import com.shuyu.gsyvideoplayer.video.base.GSYVideoView
@ -120,8 +122,6 @@ class DetailPlayerView @JvmOverloads constructor(context: Context, attrs: Attrib
} else {
hideBackBtn()
}
// unMute()
// volume.setOnClickListener { toggleMute() }
}
override fun getLayoutId(): Int {
@ -343,6 +343,24 @@ class DetailPlayerView @JvmOverloads constructor(context: Context, attrs: Attrib
}
}
override fun createNetWorkState() {
if (mNetInfoModule == null) {
mNetInfoModule = NetInfoModule(mContext.applicationContext, NetInfoModule.NetChangeListener { state ->
if (mNetSate != state) {
Debuger.printfError("******* change network state ******* $state")
mNetChanged = true
if (errorContainer.visibility == View.VISIBLE && "NONE" != state) {
seekOnStart = currentPositionWhenPlaying.toLong()
startPlayLogic()
}
}
mNetSate = state
})
mNetSate = mNetInfoModule.currentConnectionType
}
}
override fun showWifiDialog() {
val trafficVideo = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SettingsFragment.TRAFFIC_VIDEO_SP_KEY, false)
if (!trafficVideo) {
@ -610,8 +628,8 @@ class DetailPlayerView @JvmOverloads constructor(context: Context, attrs: Attrib
}
override fun netWorkErrorLogic() {
super.netWorkErrorLogic()
//super.netWorkErrorLogic()
gsyVideoManager.pause()
Utils.toast(context, "网络错误,视频播放失败")
setViewShowState(mStartButton, View.INVISIBLE)
errorContainer.visibility = View.VISIBLE