title: android:: how to add suitable delay during playing a video in VideoView
body: <p>I am a newbei to android. Currently, I am playing a video from a URL in android VideoView.
  I have search a lot in order to find out a way, how to add repetitive delay in video playing via android code.</p>
  
  <p>With Thread.sleep(3000), i can delay it only 1 time But i want to delay the video playing after every 5 seconds.</p>
  
  <p>Task:
  Condition 1: For User 1
  I have to add repetitive delay during the playing of the video; means the video will play for 5 seconds and then it will encounter a delay of approx. 4-5 seconds. In fact, i am trying to create a situation which will show the observer that there is some delay during video buffering.  </p>
  
  <p>Any solution.</p>
  
  <p>Thanks</p>
  
  <p>private void playVideo() {</p>
  
  <pre><code>    try {
      final String path = "http://daily3gp.com/vids/747.3gp";
          if (path == null || path.length() == 0) {
              Toast.makeText(CStreaming.this, "File URL/path is empty",
                      Toast.LENGTH_LONG).show();
          } 
  
          else {              
              **Thread.sleep(3000);**
              // If the path has not changed, just start the media player
              Log.v(TAG,"Thread Sleep ....3000 msec");
              if (path.equals(current) &amp;&amp; mVideoView != null) {
                  mVideoView.start();
                  mVideoView.requestFocus();
                  return;
              }
              current = path;
              Log.i(TAG,"Value of path in PlayVideo()=" + path);
              mVideoView.setVideoPath(getDataSource(path));
  
              mVideoView.start();
              mVideoView.requestFocus();
              }
  </code></pre>
  
  <p>}</p>
  
  <p>// getDataSource method which will be used by playVideo()</p>
  
  <pre><code>private String getDataSource(String path) throws IOException {
      if (!URLUtil.isNetworkUrl(path)) {
          return path;
      } else {
  
          URL url = new URL(path);
          URLConnection cn = url.openConnection();
          cn.connect();
          InputStream stream = cn.getInputStream();
          if (stream == null)
              throw new RuntimeException("stream is null");
          File temp = File.createTempFile("mediaplayertmp", "dat",this.getCacheDir());
          temp.deleteOnExit();
          String tempPath = temp.getAbsolutePath();
          FileOutputStream out = new FileOutputStream(temp);
          byte buf[] = new byte[128];
          do {
              int numread = stream.read(buf);
          Log.i(TAG,"Buffer Printing via Array: " + Arrays.toString(buf));
              if (numread &lt;= 0)
                  break;
              out.write(buf, 0, numread);
          } while (true);
          try {
              stream.close();
          } catch (IOException ex) {
              Log.e(TAG, "error: " + ex.getMessage(), ex);
          }
          return tempPath;
      }
  }
  </code></pre>