title: How to play video one by one and play/pause when scroll listview
body: <p>I want to play video which is on frontView, how to detect the view in <code>listView</code> and play when <code>getView</code> and pause when scrolled up. How to do this?</p>
  
  <p><strong>This is my code.</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
      ListView listview;
      CustomListAdapter adapter;
      public static int currentItem;
      public static ArrayList&lt;String&gt; videoLIst;
      public static MediaController mediaController ;
      boolean pauseOnScroll = true;
      boolean pauseOnFling = true;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_view);
          videoLIst = new ArrayList&lt;String&gt;();
           mediaController = new MediaController(MainActivity.this); 
          videoLIst.add("http://journey.coderspreview.com/uploads/Home_Video/mov_bbb.mp4");
          videoLIst.add("http://journey.coderspreview.com/uploads/Home_Video/mov_bbb.mp4");
          videoLIst.add("http://journey.coderspreview.com/uploads/Home_Video/mov_bbb.mp4");
          videoLIst.add("http://journey.coderspreview.com/uploads/Home_Video/mov_bbb.mp4");
          videoLIst.add("http://journey.coderspreview.com/uploads/Home_Video/mov_bbb.mp4");
          videoLIst.add("http://journey.coderspreview.com/uploads/Home_Video/mov_bbb.mp4");
          videoLIst.add("http://journey.coderspreview.com/uploads/Home_Video/mov_bbb.mp4");
          videoLIst.add("http://journey.coderspreview.com/uploads/Home_Video/mov_bbb.mp4");
          listview = (ListView) findViewById(R.id.list);
          adapter = new CustomListAdapter(MainActivity.this, videoLIst);
          // Set video link (mp4 format )
          listview.setAdapter(adapter);
          listview.setOnScrollListener(new OnScrollListener() {
  
              @Override
              public void onScrollStateChanged(AbsListView view, int scrollState) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void onScroll(AbsListView view, int firstVisibleItem,
                      int visibleItemCount, int totalItemCount) {
                  // TODO Auto-generated method stub
  
                  int firstVisibleRow = listview.getFirstVisiblePosition();
                  int lastVisibleRow = listview.getLastVisiblePosition();
  
                  for(int i=firstVisibleRow;i&lt;=lastVisibleRow;i++)
                  {
                      //Write your code here(allocation/deallocation/store in array etc.)
                      System.out.println(i + "=" + listview.getItemAtPosition(i));
                      currentItem = (int) listview.getItemAtPosition(i);
                  }
              }
          });
  
  
      }
  
      public class CustomListAdapter extends BaseAdapter {
          private Activity activity;
          private LayoutInflater inflater;
          private ArrayList&lt;String&gt; videoList;
  
          public CustomListAdapter(Activity activity, ArrayList&lt;String&gt; videoList) {
              this.activity = activity;
              this.videoList = videoList;
          }
  
          @Override
          public int getCount() {
              return videoList.size();
          }
  
          @Override
          public Object getItem(int location) {
              return videoList.get(location);
          }
  
          @Override
          public long getItemId(int position) {
              return position;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
  
              if (inflater == null)
                  inflater = (LayoutInflater) activity
                          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              if (convertView == null)
                  convertView = inflater.inflate(R.layout.activity_main, null);
  
              VideoView video = (VideoView)convertView.findViewById(R.id.VideoView);
              TextView  txvvideo =(TextView)convertView.findViewById(R.id.txvposition);
  
              txvvideo.setText("Video"+position);
  
              mediaController.setAnchorView(video);
              Log.d("video url inadapter:", ""+videoLIst.toString());
              Uri uri = Uri.parse(videoList.get(currentItem));
              video.setMediaController(mediaController);
              video.setVideoURI(uri);
              video.start();
              int pos;
              pos=video.getCurrentPosition();
  //          if(pos == currentItem)
  //          {
  //              video.pause();
  //          }
  //          video.setMediaController(mediaController);
  //          video.setVideoURI(Uri.parse(videoList.get(position)));
  //          video.start();
               return convertView;
          }
  
      }    
  
  }
  </code></pre>
  
  <p>I want to stop video when It is invisible in <code>listview</code> when I scroll it up or down.</p>