Nana Kwame
Nana Kwame

Reputation: 1309

AssetsAudioPlayer only plays the audio at last index

I'm using a listview to display images and text in my flutter app. I've stored the asset path and text in a Json file and I convert it to a list. Getting the image asset path and displaying the correct one seems to work with no issues but thats not the case in playing the audio files from their assets.

I'm using this package import 'package:assets_audio_player/assets_audio_player.dart';

declaration final AssetsAudioPlayer playAudio = AssetsAudioPlayer();

and this is main widget

 @override
 Widget build(BuildContext context) {
    Widget _buildRow(int idx) {
      for (var translations in widget.category.translations) {
        _wordList = widget.category.translations[idx];
        return Container(
          height: 88.0,
          child: Card(
            child: ListTile(
              onTap: () {
                playAudio.open(
                  Audio(_wordList.audio),
                );
                // player.play(_wordList.audio);
                log(_wordList.audio, name: 'my.other.category');
              },
              onLongPress: () {},
              leading: SizedBox(
                width: 50.0,
                height: 88.0,
                child: Image(
                  image: AssetImage(_wordList.emoji),
                  fit: BoxFit.contain,
                ),
              ),
              title: Text(
                _wordList.akan,
                style: TextStyle(fontSize: 18),
              ),
              subtitle: Text(
                _wordList.english,
                style: TextStyle(fontSize: 18, color: Colors.black),
              ),
              trailing: const Icon(Icons.play_arrow, size: 28),
            ),
          ),
        );
      }
    }

Since the image assets in the json file have no issues I don't get why the audio does I've stored them like this,

 {
  "english": "mother",
  "akan": "ɛna",
  "emoji": "assets/icons/family_mother.png",
  "audio": "assets/audio/family_mother.mp3"
},

Upvotes: 0

Views: 275

Answers (1)

Nana Kwame
Nana Kwame

Reputation: 1309

Solved it by generating a new listtile widget through iteration and then putting it into a listview

Upvotes: 1

Related Questions