Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioCache does not handle resources from a package #1785

Open
2 tasks done
MuthannaVenki opened this issue Apr 3, 2024 · 1 comment
Open
2 tasks done

AudioCache does not handle resources from a package #1785

MuthannaVenki opened this issue Apr 3, 2024 · 1 comment
Labels

Comments

@MuthannaVenki
Copy link

Checklist

  • I read the troubleshooting guide before raising this issue
  • 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//". Below code in AudioCache seems to be looking for resources in the app assets ignoring the package specification as seem in below line from audio_cache.dart file

final byteData = await loadAsset('$prefix$fileName');

Expected behaviour

Should allow resource loading from packages.

Steps to reproduce

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

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

@JesperBllnbm
Copy link

JesperBllnbm commented Apr 10, 2024

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants