exoplayer预先缓冲流导致性能问题

时间:2018-06-08 18:01:08

标签: android performance exoplayer

使用exoplayer 2.8.1,测试android API版本22.我使用以下代码构建缓存和数据源工厂:

private static final long DEFAULT_MAX_CACHE_SIZE = 20*1024*1024L;

cacheEvictor = new LeastRecentlyUsedCacheEvictor(DEFAULT_MAX_CACHE_SIZE);

cache = new SimpleCache(
        new File(context.getExternalCacheDir(), "exoplayer-cache"),
        cacheEvictor);

uncachedDataSourceFactory = new OkHttpDataSourceFactory(
        new OkHttpClient(),
        "Android.ExoPlayer",
        null);
dataSourceFactory =
        new CacheDataSourceFactory(
                cache,
                uncachedDataSourceFactory);

然后,我使用以下代码预先标准化标准HTTP音频内容:

new Thread (new Runnable () {
    public void run() {
        try {
            CacheUtil.cache(
                    new DataSpec(uri, DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH | DataSpec.FLAG_ALLOW_GZIP),
                    cache,
                    uncachedDataSourceFactory.createDataSource(),
                    null,
                    null);
        } catch (IOException e) {
            callback.invoke(false, "Error: " + e.getMessage());
        } catch (InterruptedException e) {
            callback.invoke(false, "Download interrupted");
        }
        callback.invoke(true);
    }
}).start();

这在模拟器上工作正常,但是当尝试在实际手机上执行此操作时,手机在下载缓存项目时变得非常无响应(动画下降到大约每秒4-5帧,滚动是紧张的)。为什么这会使系统变得如此缓慢,如何让它更顺畅地工作呢?

0 个答案:

没有答案