Home > other >  type 'String' is not a subtype of type 'Source
type 'String' is not a subtype of type 'Source

Time:08-04

I have url of music stored in the firestore. Below in the code I am trying to play audio as per the url but I am unable to play the audio and I am getting Unhandled Exception: type 'String' is not a subtype of type 'Source'. I am using audiplayers package.

 Row (
          mainAxisAlignment:  MainAxisAlignment.spaceBetween,
          children: [
            Text(formatTime(position)),
            Text(formatTime(duration-position)),
            CircleAvatar(
              radius: 35,
                child: IconButton(
                  icon: Icon(isPlaying ? Icons.pause: Icons.play_arrow_rounded), onPressed: () async{
                    if (isPlaying){
                      await audioPlayer.pause();
                    } else {

                 await audioPlayer.play(widget.music);
                    }

                },
                ),
            )
          ],

    )

CodePudding user response:

play method requires Source class as a parameter. E.g. with a remote url:

await audioPlayer.play(UrlSource(widget.music));
  • Related