You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter:audioPlayer.play传参报错Too many positional arguments问题求助

解决audioPlayer.play参数错误的问题

这个错误是因为你使用的新版audioplayers库(2.x及以上版本)重构了API,play方法不再接受直接的字符串参数,而是要求传入对应的音频源对象。

解决步骤:

  • 确保已导入正确的类:
import 'package:audioplayers/audioplayers.dart';
  • 修改播放代码,将URL字符串包装为UrlSource对象传入:
String url = _loadedAudio[index]['file'];
await audioPlayer.play(UrlSource(url));

如果是本地文件或项目资源音频,可对应使用DeviceFileSource或AssetSource,服务器获取的网络音频用UrlSource即可。

内容的提问来源于stack exchange,提问作者mohamed yassine

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 03:20:33