title: How to play local files using exoplayer?
body: <p>I want to use exoPlayer to play local files(in internal or external storage). I have tried some code but didn't find anything useful.
  code:</p>
  <pre><code>getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
      String filePath = Constant.allMediaList.get(position).toString();
      Uri videoUrl = Uri.parse(filePath);
      Log.d(&quot;filePathLocation&quot;,filePath);
      simpleExoPlayer = new SimpleExoPlayer.Builder(this).build();
      DataSpec dataSpec = new DataSpec(videoUrl);
      final FileDataSource fileDataSource = new FileDataSource();
      try {
          fileDataSource.open(dataSpec);
      } catch (FileDataSource.FileDataSourceException e) {
          e.printStackTrace();
      }
      DataSource.Factory factory = new DataSource.Factory() {
          @Override
          public DataSource createDataSource() {
              return fileDataSource;
          }
      };
      simpleExoPlayer.prepare(buildMediaSourceNew(videoUrl));
      playerView.setPlayer(simpleExoPlayer);
      simpleExoPlayer.setPlayWhenReady(true);
  </code></pre>
  <p><code>buildMediaSourceNew()</code>:</p>
  <pre><code>    private MediaSource buildMediaSourceNew(Uri uri){
      DataSource.Factory datasourceFactroy = new DefaultDataSourceFactory(this,
              Util.getUserAgent(this,&quot;Your App Name&quot;));
      return new ExtractorMediaSource.Factory(datasourceFactroy).createMediaSource(uri);
  }
  </code></pre>
  <p>after using this code some files can be played and some not. For example:<br>
  1st file Location:<br></p>
  <pre><code>/storage/emulated/0/Download/Short Animated Film.mp4
  </code></pre>
  <p>2nd file location:<br></p>
  <pre><code>/storage/emulated/0/browser/#1 Django tutorials _ What is Django_ _ Python Web Framework.mp4
  </code></pre>
  <p>1st file can be played but for 2nd file below errors occured.<br>
  <b>if file name contains &quot;#&quot; or &quot;?&quot; exoplayer can't play it.</b></p>
  <pre><code>    2020-09-18 20:40:56.985 10985-11347/com.example.learning E/ExoPlayerImplInternal: Source error
    com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: uri has query and/or fragment, which are not supported. Did you call Uri.parse() on a string containing '?' or '#'? Use Uri.fromFile(new File(path)) to avoid this. path=/storage/emulated/0/browser/,query=null,fragment=1 Django tutorials _ What is Django_ _ Python Web Framework.mp4
      at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:97)
      at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:177)
      at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83)
      at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:956)
      at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
      at java.lang.Thread.run(Thread.java:764)
   Caused by: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: uri has query and/or fragment, which are not supported. Did you call Uri.parse() on a string containing '?' or '#'? Use Uri.fromFile(new File(path)) to avoid this. path=/storage/emulated/0/browser/,query=null,fragment=1 Django tutorials _ What is Django_ _ Python Web Framework.mp4
      at com.google.android.exoplayer2.upstream.FileDataSource.openLocalFile(FileDataSource.java:112)
      at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:88)
      at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:177) 
      at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83) 
      at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:956) 
      at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
      at java.lang.Thread.run(Thread.java:764) 
   Caused by: java.io.FileNotFoundException: /storage/emulated/0/browser: open failed: EISDIR (Is a directory)
      at libcore.io.IoBridge.open(IoBridge.java:485)
      at java.io.RandomAccessFile.&lt;init&gt;(RandomAccessFile.java:288)
      at java.io.RandomAccessFile.&lt;init&gt;(RandomAccessFile.java:151)
      at com.google.android.exoplayer2.upstream.FileDataSource.openLocalFile(FileDataSource.java:108)
      at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:88) 
      at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:177) 
      at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83) 
      at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:956) 
      at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
      at java.lang.Thread.run(Thread.java:764) 
   Caused by: android.system.ErrnoException: open failed: EISDIR (Is a directory)
      at libcore.io.IoBridge.open(IoBridge.java:475)
      at java.io.RandomAccessFile.&lt;init&gt;(RandomAccessFile.java:288) 
      at java.io.RandomAccessFile.&lt;init&gt;(RandomAccessFile.java:151) 
      at com.google.android.exoplayer2.upstream.FileDataSource.openLocalFile(FileDataSource.java:108) 
      at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:88) 
      at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:177) 
      at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83) 
      at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:956) 
      at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
      at java.lang.Thread.run(Thread.java:764) 
  </code></pre>
  <p>How to avoid this error?</p>