I'm trying to create a fullscreen video feed on Android.
I decided to use a ListView
and each item is a TextureView
. Because it's fullscreen, at a given moment, we always have one and only one item displayed.
When the TextureView
is available, I create a MediaPlayer
and play the video on the surface. It works pretty well.
When I reach the bottom of my list, I load more data from the server. When the new data is loaded, I call the notifyDataSetChanged()
of my BaseAdapter
and it recreates the views for each visible item.
The problem is that it make the current video "blink" (when the view is recreated, the video disappears and then reappears).
I don't really know how to solve this problem: the ListView
always recreates the item views when the dataset changes.
I feel like using a ListView
is the right solution here because I display a list of video items but maybe I'm on the wrong path...
ListView
not to recreate the current item's view?)ListView
? If yes, what should I be looking at?Thanks.
You should use the View Holder pattern. In your case, add an id of the currently displayed video to the holder, this will allow you tu return the convertView unchanged if it is already displaying the video.
Here is a sample of (untested) code showing the idea :
public View getView (int position, View convertView, ViewGroup parent) {
Holder holder;
if(convertView != null) {
holder = (Holder) convertView.getTag();
if(holder.displayedContent == getContentToDisplay(position)) {
// the view we were asked to convert is already displaying
// the good video, no need to change anything to it !
return convertView;
} else {
// convert the view by displaying the new video
}
} else {
// create a new view !
}
}
private static class Holder {
int displayedContent;
// + references to the views
}