Skip to content Skip to sidebar Skip to footer

Automatically Playing Video In Listview/scrollview Similar To Facebook

I need Video to play automatically in listview/scrollview, if view contains video. This is ver much similar with facebook. If user scrolls down and visible area contains video that

Solution 1:

Please follow the points

  1. First you need to add a scroll listener into RecyclerView
  2. Then through the listener update your RecyclerView adapter

    protectedvoidonListViewUpdate(finalint position, final Object object) {
        finalRecyclerViewview= mView;
        LinearLayoutManagerlayoutManager= ((LinearLayoutManager)view.getLayoutManager());
        finalViewconvertView= layoutManager.findViewByPosition(position);
        intfirstVisiblePosition= layoutManager.findFirstCompletelyVisibleItemPosition();
        intlastVisiblePosition= layoutManager.findLastCompletelyVisibleItemPosition();            
    
        if (firstVisiblePosition <= position && position <= lastVisiblePosition) {
            // this is the convertView that you previously returned in getView// just fix it (for example:)Threadthread=newThread(){
                @Overridepublicvoidrun() {
                    super.run();
    
                    runOnUiThread(newRunnable() {
                        @Overridepublicvoidrun() {
                            adapter.updateRow(adapter.getItem(position), convertView, object);
                        }
                    });
                }
            };
            thread.start();
        } else {
            // just update your data set, UI will be updated automatically in next// getView() call
            adapter.updateData(position, object);
        }
    }
    
  3. From the adapter update the current visible view from updateRow() method.

Job Done :)

Post a Comment for "Automatically Playing Video In Listview/scrollview Similar To Facebook"