V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
55z55
V2EX  ›  Flutter

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

  •  
  •   55z55 · 2023-06-02 23:57:27 +08:00 · 1221 views
    This topic created in 534 days ago, the information mentioned may be changed or developed.
    写了一个在 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 replies    2023-06-03 14:40:48 +08:00
    huohei
        1
    huohei  
       2023-06-03 00:18:33 +08:00 via iPhone
    报错信息呢
    55z55
        2
    55z55  
    OP
       2023-06-03 00:38:15 +08:00
    @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  
       2023-06-03 01:30:56 +08:00 via iPhone
    55z55
        4
    55z55  
    OP
       2023-06-03 14:40:48 +08:00 via Android
    @huohei 谢谢,已搞定,代码看这里🤡

    https://github.com/wscoding/win-muyu
    About   ·   Help   ·   Blog   ·   API   ·   FAQ   ·   Tools   ·   3006 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 14:47 · PVG 22:47 · LAX 06:47 · JFK 09:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.