首页 > 解决方案 > Android exoplayer v2.11.5 & v2.13.2 UI 延迟时​​调用准备

问题描述

在我的应用程序中,我正在构建一个视频播放工具,用户可以在其中从 recyclerview 中选择和播放不同的视频。我注意到,在 ExoPlayer 的 v2.11.5 和 v2.13.2 版本中,一旦我调用方法准备,UI 就会滞后。我尝试将其注释掉,并且日志猫显示没有 GC 提要(AllocSpace 对象)。我还尝试在 ExoPlayer 上设置 setLoadControl() 方法,但效果不佳。调用准备好的方法后,有什么方法可以消除滞后。您可以在下面找到启动视频的代码。

 fun prepareSource(source: String) {
        if (source.isBlank() || this.mSource == source) return
        mSource = source
        onLoading.value = true
        val hlsMediaSource: HlsMediaSource = HlsMediaSource.Factory(dataSourceFactory)
            .setAllowChunklessPreparation(true)
        .   createMediaSource(MediaItem.fromUri(source))
        player.setMediaSource(hlsMediaSource)
       // player.prepare()  -> This method causes the UI to freeze, commenting it out the UI works as excepted
       // emit default values
       onPlaybackSpeed.value = Global.PLAYER_DEFAULT_PLAYBACK_SPEED
       onVolume.value = Global.PLAYER_DEFAULT_VOLUME
}

标签: androidexoplayer

解决方案


推荐阅读