title: how to update setdatasource of running mediaplayer in android
body: <p>I create a mp3 file by writing OutputStream(Bytes array) and then put mp3 file path in setDataSource of media player then media player is start.</p>
  
  <p>But when I update running mp3 file by appending stream(Bytes array) at runtime then media player is not updated. So how can I solve this issue.
  please help regarding this issue.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>InputStream inputStream = socket.getInputStream();
  
  ByteArrayOutputStream dataOutputStream = new ByteArrayOutputStream();     
  int count=0
      while(true){
                  byte[] buffer = new byte[1096*50];
                  int bytesRead = inputStream.read(buffer);
                  dataOutputStream.write(buffer, 0, bytesRead);
  
                  String fpath = "/sdcard/" + "sha" + ".txt";
                  File file = new File(fpath);
                  // If file does not exists, then create it
  
      if (!file.exists()) {                             
                          file.createNewFile();
                          }
      try{
  
          OutputStream outputStream = new FileOutputStream(fpath);
          dataOutputStream.writeTo(outputStream);
          count++;
             if (count==500){
                 playMp3(fpath);
                            }
                   }
  
  
       private void playMp3(String path) {
  
          try {
              MediaPlayer mediaPlayer = new MediaPlayer();
              mediaPlayer.reset();
              mediaPlayer.setDataSource(path);
              mediaPlayer.prepare();
              mediaPlayer.start();
  
          } catch (IOException ex) {
              String s = ex.toString();
              ex.printStackTrace();
          }
      }
  </code></pre>