Just_audio: setFilePath method fails if the file path contains '?' or '#'

Created on 20 Apr 2020  Â·  6Comments  Â·  Source: ryanheise/just_audio

Describe the bug
If setFilePath method is called with a path which contains '?' or '#' it fails with the following error.

Error messages

E/ExoPlayerImplInternal(26415): Source error.
E/ExoPlayerImplInternal(26415): com.google.android.exoplayer2.upstream.w$a: com.google.android.exoplayer2.upstream.w$a: 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/Music/Music/The Chainsmokers/2014 - ,query=null,fragment=SELFIE (Instrumental Mix) (Single)/01. #SELFIE (Instrumental Mix).mp3
E/ExoPlayerImplInternal(26415):     at com.google.android.exoplayer2.upstream.w.a(:97)
E/ExoPlayerImplInternal(26415):     at com.google.android.exoplayer2.upstream.r.a(:177)
E/ExoPlayerImplInternal(26415):     at com.google.android.exoplayer2.upstream.d0.a(:83)
E/ExoPlayerImplInternal(26415):     at d.f.a.b.h1.b0$a.a(:961)
E/ExoPlayerImplInternal(26415):     at com.google.android.exoplayer2.upstream.a0$d.run(:391)
E/ExoPlayerImplInternal(26415):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal(26415):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal(26415):     at java.lang.Thread.run(Thread.java:764)
E/ExoPlayerImplInternal(26415): Caused by: com.google.android.exoplayer2.upstream.w$a: 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/Music/Music/The Chainsmokers/2014 - ,query=null,fragment=SELFIE (Instrumental Mix) (Single)/01. #SELFIE (Instrumental Mix).mp3
E/ExoPlayerImplInternal(26415):     at com.google.android.exoplayer2.upstream.w.a(:112)
E/ExoPlayerImplInternal(26415):     at com.google.android.exoplayer2.upstream.w.a(:88)
E/ExoPlayerImplInternal(26415):     ... 7 more
E/ExoPlayerImplInternal(26415): Caused by: java.io.FileNotFoundException: /storage/emulated/0/Music/Music/The Chainsmokers/2014 - : open failed: ENOENT (No such file or directory)
E/ExoPlayerImplInternal(26415):     at libcore.io.IoBridge.open(IoBridge.java:485)
E/ExoPlayerImplInternal(26415):     at java.io.RandomAccessFile.<init>(RandomAccessFile.java:288)
E/ExoPlayerImplInternal(26415):     at java.io.RandomAccessFile.<init>(RandomAccessFile.java:151)
E/ExoPlayerImplInternal(26415):     at com.google.android.exoplayer2.upstream.w.a(:108)
E/ExoPlayerImplInternal(26415):     ... 8 more
E/ExoPlayerImplInternal(26415): Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)

Expected behavior
setFilePath should work with file paths containing either '?' or '#'

Desktop (please complete the following information):

  • OS: Microsoft Windows [Version 10.0.18363.778]
  • chrome+ 80.0.3987.163 (Official Build) (64-bit)

Smartphone (please complete the following information):

  • Device: Samsung Galaxy A50
  • OS: Android 9

Flutter SDK version

[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18363.778], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 3.6)
[√] VS Code (version 1.44.2)
[√] Connected device (1 available)

• No issues found!
bug

All 6 comments

Interesting. Since I convert the file path to a file:// URL first, this might be fixable by encoding those special characters to make it a proper URL.

As a temporary workaround/experiment, you could try replacing # by %23 and replacing ? by %3F . If that works for you, I'll implement directly in the plugin (for the full range of special characters of course).

@ryanheise Thanks for your quick response! I can confirm encoding those characters the way you mentioned works.

I've tried a fix on git master. Can you give it a try and let me know if it works for you?

Yeah sure. I'll let you know about the result soon.

I tried my app with the master version and it's working.
Thank you!

Great! I'll include it in the next release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smkhalsa picture smkhalsa  Â·  6Comments

ryanheise picture ryanheise  Â·  13Comments

lain-ke picture lain-ke  Â·  4Comments

ryanheise picture ryanheise  Â·  7Comments

cnttechio picture cnttechio  Â·  13Comments