I have a listview and it has custom adapter. Adapter keeps videoview items on it. On list, when I click a videoview it is starting to play that is working ok. But after when I click next videoview, the previous one continue to playing. Here is my question: how can I stop previous videoview, when I clicked next one ? Thanks.
Custom Adapter Codes:
public class Node_Content_Adapter extends ArrayAdapter<Node_Content_Item> {
Context context;
int ResourceId;
public Node_Content_Adapter(Context context, int layoutResourceId,
List<Node_Content_Item> objects) {
super(context, layoutResourceId, objects);
this.ResourceId = layoutResourceId;
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
final Node_Content_Item itemObj = getItem(position);
View listItemView;
LayoutInflater layoutInflator = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(convertView==null)
listItemView = layoutInflator.inflate(ResourceId, null);
else
listItemView=convertView;
final RelativeLayout rlayout=(RelativeLayout) listItemView.findViewById(R.id.rlayout);
final VideoView video=(VideoView)listItemView.findViewById(R.id.videoViewMain);
//There is a layout over videoview and when layout clicked video starting to play
rlayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(video.isPlaying())
{
video.stopPlayback();
}
else
{
Uri uri=Uri.parse(itemObj.getVideourl());
video.setVideoURI(uri);
video.start();
}
}
});
return listItemView;
}