求助 flutter 代码 按钮提示音 问题

330 天前
 55z55
写了一个在 Windows 平台上的应用

想在这个事件里面添加一个点击的提示音,

onTap: () {
//点击时播放背景音乐
animationController.forward();
addOverLay(context);
},

用的库都是兼容 win 平台的,试了好多都不行,
新版 audioplayers 没声音+报错
旧版 audioplayers 没声音

试了好多遍,点击了就是没有声音

onTap: () {
AudioPlayer _player;
_player = new AudioPlayer();
_player.play('assets/music/my.mp3');
//点击时后台播放提示音
addOverLay(context);

},

能搜到的教程都是特别旧的,问了 gpt4.0 代码没问题就是没声音

我裂开了
1010 次点击
所在节点    Flutter
4 条回复
huohei
330 天前
报错信息呢
55z55
330 天前
@huohei 第一种写法:

onTap: () {
AudioPlayer audioPlayer = AudioPlayer();
//点击时播放背景音乐
audioPlayer.play('click.mp3');
},

click.mp3 处报错:The argument type 'String' can't be assigned to the parameter type 'Source'.

第二种写法:

onTap: () {
AudioCache audioCache = AudioCache();
//点击时播放背景音乐
audioCache.play('click.mp3');
},

.play 处报错:The method 'play' isn't defined for the type 'AudioCache'.
Try correcting the name to the name of an existing method, or defining a method named 'play'.
huohei
330 天前
55z55
330 天前
@huohei 谢谢,已搞定,代码看这里🤡

https://github.com/wscoding/win-muyu

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/945377

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX