audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

AudioCache does not handle resources from a package

Open MuthannaVenki opened this issue 10 months ago • 1 comments

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//". 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

MuthannaVenki avatar Apr 03 '24 04:04 MuthannaVenki

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

JesperBllnbm avatar Apr 10 '24 11:04 JesperBllnbm