当前位置:网站首页>When the recyclerview plays more videos, the problem of refreshing the current video is solved.

When the recyclerview plays more videos, the problem of refreshing the current video is solved.

2022-06-11 05:36:00 Cockroach bully BBQ

The background of the story is like this : What the project does is a short video playback function similar to Tiktok , Click to enter the video details , Play full screen , Then slide up and down to switch video , It's using RecyclerView Combined with Alibaba cloud player Video streaming , Because the background is a paging interface , Therefore, more data needs to be loaded when there is almost no data on the slide . It used to be : 

this.list.clear(); // Clear data source

this.list.addAll(list); // Update data source

adapter.notifyDataSetChanged();// Refresh List

Then there is a small problem , Request per page 10 strip , If the home page currently has a total of 10 A video , From the home page, directly click Page 10 individual , That is, currently playing the 10 A video , Then directly request the next page of video data , Using the above code will cause the currently playing video to restart playing , The experience is not very good , And as we all know notifyDataSetChanged() refresh all , Efficiency is the lowest . Just want to use RecyclerView To replace the local refresh , namely

notifyItemRangeChanged(this.list.size()-list.size(),this.list.size());  // Only refresh and load the extra data list 

Then run and find no effect , Many data slides do not appear ! Muddled ing...  (tip: Before, I usually used RecyclerView Make a list , This is the first time to do this kind of complex video streaming ~)

// Finally, it was changed to this kind of writing , Successfully refresh data , At the same time, the progress of the currently playing video will not be interrupted :

this.list.addAll(list);// Update data source 
notifyItemRangeInserted(this.list.size()-list.size(),this.list.size());// Update the number of lists 
notifyItemRangeChanged(this.list.size()-list.size(),this.list.size());// Update list data 

seeing the name of a thing one thinks of its function , Insert the number of lists first , Then perform a local refresh operation , Make a note of , Why haven't you seen the source code yet , Let's settle it first ,over.

 

原网站

版权声明
本文为[Cockroach bully BBQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020538031591.html