所以我使用Flutter包audioplayers在我的应用程序上播放音频,但问题是导入包后,它说找不到play()函数。
下面是代码:
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
void main() {
runApp(const XlyophoneApp());
}
class XlyophoneApp extends StatelessWidget {
const XlyophoneApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: TextButton(
child: const Text('Click Me'),
onPressed: () {
final player = AudioCache();
player.play("note1.wav"); // Here it says that the play function is not defined
},
),
),
),
),
);
}
}
2条答案
按热度按时间ergxz8rk1#
下面的代码不再有效
您可以执行以下操作,而不是上面的代码
Source
a8jjtwal2#
按下时:(){音频播放器播放器=音频播放器();(资产来源("注1.wav"));player.play(AssetSource("note1.wav")); },