bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
1.97k stars 842 forks source link

Sound not found inside cache folder - app crash #1778

Open prok155 opened 6 months ago

prok155 commented 6 months ago

Checklist

Current bug behaviour

I published my app to google play store, I use crashlytics and I see following stacktraces:

PlatformException(AndroidAudioError, Failed to set source. For troubleshooting, see: https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, java.io.FileNotFoundException: /data/user/0/com.companyname.myPackageName/cache/audio/AnswerCorrect.mp3: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:574) at java.io.FileInputStream.<init>(FileInputStream.java:160) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1272) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1243) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1208) at ra.d.a(Unknown Source:7) at qa.m.h(Unknown Source:10) at qa.s.K(Unknown Source:15) at pa.m.L(Unknown Source:552) at pa.m.o(Unknown Source:0) at pa.m$b.b(Unknown Source:14) at pa.m$b.invoke(Unknown Source:4) at pa.m$d.invokeSuspend(Unknown Source:16) at kotlin.coroutines.jvm.internal.a.resumeWith(Unknown Source:11) at ba.y0.run(Unknown Source:93) at ga.o$a.run(Unknown Source:3) at ia.k.run(Unknown Source:2) at ia.a.R(Unknown Source:0) at ia.a$c.d(Unknown Source:14) at ia.a$c.p(Unknown Source:28) at ia.a$c.run(Unknown Source:0) Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Linux.open(Native Method) at libcore.io.ForwardingOs.open(ForwardingOs.java:563) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274) at libcore.io.ForwardingOs.open(ForwardingOs.java:563) at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8641) at libcore.io.IoBridge.open(IoBridge.java:560) ... 20 more , null)

I have my sound files in my 'assets', but it seems that your package creates sounds files inside temp cache directory, look : java.io.FileNotFoundException: /data/user/0/com.companyname.myPackageName/cache/audio/AnswerCorrect.mp3.

Android sometimes deletes cache directory, for example when there is not enough space on the disk, you should keep those temp files inside app data directory instead of temp folder.

Expected behaviour

You should not keep temp files inside cache folder, it will fix this issue.

Steps to reproduce

  1. Execute flutter run on the code sample
  2. ...
  3. ...

Code sample

static void playSound() async { final player = AudioPlayer(); await player.play(AssetSource('audio/AnswerCorrect.mp3')); }

Affected platforms

Android

Platform details

No response

AudioPlayers Version

6.0.0

Build mode

debug, profile, release

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

my relevant logs
Full Logs ``` my full logs or a link to a gist ``` Flutter doctor: ``` Output of: flutter doctor -v ```

Related issues / more information

No response

Working on PR

no way

prok155 commented 6 months ago

If I do somthing wrong, please explain me how can I fix this issue.

IRiS-Sk13 commented 2 weeks ago

+1 I'm facing this a lot too