Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带有ExoPlayer/VideoView的RecyclerView性能不佳_Android_Android Videoview_Exoplayer - Fatal编程技术网

Android 带有ExoPlayer/VideoView的RecyclerView性能不佳

Android 带有ExoPlayer/VideoView的RecyclerView性能不佳,android,android-videoview,exoplayer,Android,Android Videoview,Exoplayer,我想在我的RecyclerView项目中播放视频,有点像Instagram。一次只展开一个项目,因此视频不必同时播放 我现在正在使用ExoPlayer。我的物品中有一个PlayerView用于回收视图 问题是,我的播放器性能很差,滚动和扩展时性能很差。在没有加载和播放视频的情况下,项目中的播放器的性能已经很差了,但加载后性能更差 我也尝试过VideoView,但似乎没什么不同 为了获得更好的性能,我已经做了以下工作: recyclerView.setHasFixedSize(true); rec

我想在我的RecyclerView项目中播放视频,有点像Instagram。一次只展开一个项目,因此视频不必同时播放

我现在正在使用ExoPlayer。我的物品中有一个PlayerView用于回收视图

问题是,我的播放器性能很差,滚动和扩展时性能很差。在没有加载和播放视频的情况下,项目中的播放器的性能已经很差了,但加载后性能更差

我也尝试过VideoView,但似乎没什么不同

为了获得更好的性能,我已经做了以下工作:

recyclerView.setHasFixedSize(true);
recyclerView.setItemViewCacheSize(10);
recyclerView.setDrawingCacheEnabled(true);
recyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
adapter.hasStableIds();
这有一点帮助,但并不能解决性能问题

知道问题出在哪里吗?我很欣赏你的想法

编辑:

这是我设置ExoPlayer的方法:

public void showTutuorItems(Context context, Boolean show, String resource) {
        if (show) {
            seperator.setVisibility(View.VISIBLE);
            lytTutor.setVisibility(View.VISIBLE);

            playerView = itemView.findViewById(R.id.exoPlayer);
            playerView.setUseController(false);

            playerView = itemView.findViewById(R.id.exoPlayer);
            playerView.setUseController(false);

            SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(
                    new DefaultRenderersFactory(context),
                    new DefaultTrackSelector(), new DefaultLoadControl());

            playerView.setPlayer(player);
            player.setPlayWhenReady(true);
            player.seekTo(0, 0);
            player.setRepeatMode(Player.REPEAT_MODE_ALL);
            player.setVolume(0);

            Uri uri = Uri.parse(resource);
            MediaSource mediaSource = buildMediaSource(uri);
            player.prepare(mediaSource, true, false);

            player.addListener(new Player.EventListener() {
                //...
            }


        } else {
            seperator.setVisibility(View.GONE);
            lytTutor.setVisibility(View.GONE);
        }
    }

    private MediaSource buildMediaSource(Uri uri) {

        return new ExtractorMediaSource.Factory(
                new DefaultHttpDataSourceFactory("exoplayer-codelab")).
                createMediaSource(uri);
    }
这是在我的OnCreateViewHolder中调用此方法的步骤:

if (workout.getCurrentExercsise().getTutor() != null) {
        holder.showTutuorItems(activity, true, workout.getCurrentExercsise().getTutor().getItems().get(0).getResource());
    } else {
        holder.showTutuorItems(activity, false, null);
    }

在我的OnBindViewHolder中,有一些UI内容和处理展开/折叠功能。这不应该导致问题,因为没有ExoPlayer,它工作得很好。

请提供适配器的代码,特别是bindView方法。谢谢您的帮助,但说起来容易做起来难。那里有很多东西,但这不应该是问题的一部分,因为没有ExoPlayer,这段代码工作得很好看看github.com/eneim/toro,试试看?@Jonas我也面临同样的问题。你是如何解决这个问题的?