title: Android MediaPlayer won't play music from URL
body: <p>I have a server side webapp which provides file upload and download functionality and an Android app which uploads music files onto the web site and then requests uploaded files by some URL.</p>
  
  <p>My URL is structured like: <code>http://mywebsite:8080/api/v1/files/fileById?fileId=&lt;file_id&gt;</code></p>
  
  <p>When I'm trying to get a file from a web browser, it works fine; the browser downloads file and the OS can play it. But when I'm trying to put URL described before into MediaPlayer as a datasource, I'm getting <code>java.io.IOException: setDataSource failed.</code></p>
  
  <p>The code of MediaPlayer usage:</p>
  
  <pre><code>private void startPlaying(Uri fileUri) {
      mediaPlayer = new MediaPlayer();
      mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  
      try {
          mediaPlayer.setDataSource(this, fileUri);
          mediaPlayer.prepareAsync();
          mediaPlayer.setOnPreparedListener(preparedPlayer -&gt; preparedPlayer.start());
      }
      catch (IOException e) {
          LogUtil.loge(LOG_TAG, e);
          stopPlaying();
          return;
      }
  
      mediaPlayer.setOnCompletionListener(mp -&gt; stopPlaying());
  }
  
  private void stopPlaying() {
      if (mediaPlayer == null) { return; }
      mediaPlayer.stop();
      mediaPlayer.reset();
      mediaPlayer.release();
      mediaPlayer = null;
  }
  </code></pre>
  
  <p>UPD: maybe I have to implement direct links to the files on a server side. all the samples for playing music from URL are requesting direct URL to the file.</p>
  
  <p>Any suggestions?</p>