使用AudioPlayers从按钮中播放单个音符
我正在对AudioPlayers软件包进行过时的教程,并尝试在按下按钮时播放单个音符。我无法让它上班,有人可以帮忙吗
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: TextButton(
onPressed: () {
final player = AudioCache();
player.play('note1.wav'); //ERROR THAT 'play' method is not valid
},
child: Text('Click Me'),
),
),
),
),
);
}
}
I am doing an outdated tutorial on the audioplayers package and just trying to play a single note from when the button is pressed. I am not able to get it to work, can someone please help
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: TextButton(
onPressed: () {
final player = AudioCache();
player.play('note1.wav'); //ERROR THAT 'play' method is not valid
},
child: Text('Click Me'),
),
),
),
),
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了从资产中播放声音,您需要一个
audioplayer
并将资产设置为其。In order to play sound from assets, you need a
AudioPlayer
and set asset to it.终于找到了修复程序,问题与新版本的听力播放器有关,而无需导入各种功能
Finally found the fix, the problem all had to do with the new version of audioplayers having all the functions in one class without having to import seperatly audiocache