V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
55z55
V2EX  ›  Flutter

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

  •  
  •   55z55 · 300 天前 · 976 次点击
    这是一个创建于 300 天前的主题,其中的信息可能已经有所发展或是发生改变。
    写了一个在 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 代码没问题就是没声音

    我裂开了
    4 条回复    2023-06-03 14:40:48 +08:00
    huohei
        1
    huohei  
       300 天前 via iPhone
    报错信息呢
    55z55
        2
    55z55  
    OP
       300 天前
    @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
        3
    huohei  
       300 天前 via iPhone
    55z55
        4
    55z55  
    OP
       299 天前 via Android
    @huohei 谢谢,已搞定,代码看这里🤡

    https://github.com/wscoding/win-muyu
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1146 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:36 · PVG 02:36 · LAX 11:36 · JFK 14:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.