Playing video using textureview in recyclerview

前端 未结 3 1387
清歌不尽
清歌不尽 2020-12-07 16:26

I am trying to implement a list with videos like vine or Instagram app. Where they play video plays when list item is shown or fully visible and video pauses when list item

3条回答
  •  执念已碎
    2020-12-07 16:44

    Why don't you add the custom video view in the layout file 'view_main' itself. Check the visibility of the video view and play only if the view is visible.

    public static boolean isViewVisible(View subView, View parentView) {
        Rect scrollBounds = new Rect();
        parentView.getHitRect(scrollBounds);
        if (subView.getLocalVisibleRect(scrollBounds)) {
            return true;
        }
        return false;
    }
    

    Code for checking visiblity. Call this in scroll state changed listener when the scroll state is idle.

    Also you will have to use an AsyncTask for downloading videos ,but only download one video at a time or you might get out of memory error.

提交回复
热议问题