When code that uses audio_players is imported via a package, it is not possible to point to the assets directory of the imported package #1656
JosephCarrington
started this conversation in
General
Replies: 1 comment
-
I came across this problem, and you can work around it like so: final audio = AudioPlayer();
// You must set the cache prefix to '' (the default of 'assets/' breaks this)
audio.audioCache = AudioCache(prefix: '');
// Then instead of using 'assets/your_source.mp3' use the full name 'packages/.../assets/your_sound.mp3'
audio.play(AssetSource('packages/your_package/assets/your_sound.mp3')); Flutter will load assets from within packages if you prefix with the 'packages/', but this library makes that a little difficult, because the AudioCache always prefixes your asset names with 'assets/' unless you specify your own cache. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checklist
Use case / Problem
I am writing a game that needs to be imported by another codebase, so it is a package. The game uses audio assets. However, because it is imported by another codebase, there is no way for the code I am writing to reference it's own assets folder, it is only able to reference the assets folder of the application that is importing the package.
Now, the codebase that is importing my game has to go through the process of copying all the audio assets from my game into their assets folder and make sure that the paths match exactly.
It would be nice if I could have my package reference it's own assets folder.
Proposal / Solution
With Flame, one can create new instances of the Images Cache and Sprite cache like so:
So something like that would be nice. As of now, one must supply a
Source
to the AudioPlayers.play() function, but no source is able to reference the packages asset directory, only the assets directory of whatever code happens to be the code that imported the package, or the user's device's user's folder. (eg, next to their pictures, downloads, etc).Example Code
Example Code
Affected platforms
Android, iOS
Platform details
No response
Audio Files/URLs/Sources
No response
Mockups
No response
Related issues / more information
Maybe #339 ?
Working on PR
no way
Beta Was this translation helpful? Give feedback.
All reactions