I've got a problem with my first flutter application since one week.
I was trying to build an app that consist of clicking on some movie phrases and the app play the corresponding audio phrase. Everything is in the app, the only audio phrase (for the moment) is in "assets/audio/soundname.mp3".
The problem is, when I click on the textual phrase, I wait between 8 and 9 seconds before the audio phrase starts to play.
So I've heard about using the audio_cache feature to "preload" the audio during app launching, and be able to get an instant response when I click on the text.
But it doesn't work.
I did everything right like importing, managing assets in pub yaml, checking folders etc, but I still have the problem.
I'm not accommodate to stack overflow, I know they are more strict than in Reddit in terms of writing an issue in a good way, so be gentle with ahah.
Anyway, this is an extract of my code, from the importation of packages, to the playing function :
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
class RepliqueWidget extends StatefulWidget {
final int backgroundColor;
final int shadowColor;
String imageAssetPath;
String nomPersonnage;
String texteReplique;
String audio;
RepliqueWidget(
{Key? key,
required this.backgroundColor,
required this.shadowColor,
required this.imageAssetPath,
required this.nomPersonnage,
required this.texteReplique,
required this.audio})
: super(key: key);
@override
_RepliqueWidgetState createState() => _RepliqueWidgetState();
}
class _RepliqueWidgetState extends State<RepliqueWidget> {
static AudioCache player = new AudioCache();
@override
void initState() {
super.initState();
player.load(widget.audio);
}
@override
Widget build(BuildContext context) {
final phraseAudioPath = widget.audio;
return GestureDetector(
onTap: () => player.play(phraseAudioPath),
child: Container(
I've already check like 5 posts about small audio delays with flutter but nothing related to my problem.
Thx in advance !