audioplayers
audioplayers copied to clipboard
AudioCache does not handle resources from a package
Checklist
- [X] I read the troubleshooting guide before raising this issue
- [X] I made sure that the issue I am raising doesn't already exist
Current bug behaviour
Add an audio resource to a package and try loading it from the app which uses the package. E.g. AudioPlayer().play(resourcePath) where the path is "packages/
final byteData = await loadAsset('$prefix$fileName');
Expected behaviour
Should allow resource loading from packages.
Steps to reproduce
- Execute
flutter run
on the code sample - ...
- ...
Code sample
Code sample
import 'package:audioplayers/audioplayers.dart';
void main() {
AudioPlayer().play('packages/<package name>/assets/sound/soundfile.mp3');
}
Affected platforms
Android, iOS, web, Windows, Linux, macOS
Platform details
No response
AudioPlayers Version
6.0.0
Build mode
No response
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
That actually works, I think you need to overwrite the default asset path:
AudioCache.instance.prefix = 'packages/yourPackage/';
and then use:
AudioPlayer().play('assets/sound/soundfile.mp3');
your example will try to play:
'assets/packages/<package name>/assets/sound/soundfile.mp3')