处理在子线程调用ExoPlayer方法报错和限制预加载视频50M

This commit is contained in:
Jack
2020-02-26 15:38:53 +08:00
parent 69b8155dcd
commit bc28e08b3f
3 changed files with 13 additions and 6 deletions

View File

@ -23,11 +23,14 @@ import java.util.concurrent.atomic.AtomicBoolean
object ExoCacheManager {
private val threads = ConcurrentHashMap<String, AtomicBoolean>()
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(),

View File

@ -39,9 +39,9 @@ public class CustomManager extends GSYVideoBaseManager {
private static Map<String, CustomManager> 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() {

View File

@ -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())
}
}
}