enter image description here大家好,我在 Flutter 应用程序(XYLOPHONE 应用程序,在此捕获)上播放声音时遇到问题。首先,当我按下每个播放不同声音的彩色按钮时,声音播放正常。但几秒钟后没有声音播放。这是 RUN 面板中错误消息的捕获。什么意思???
import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';
void main() {
runApp(XylophoneApp());
}
class XylophoneApp extends StatelessWidget {
void soundNumber(int num) {
final player = AudioCache();
player.play('note$num.mp3');
}
Expanded playSound({Color color, int colorNumber}) {
return Expanded(
child: Container(
child: FlatButton(
onPressed: () {
soundNumber(colorNumber);
},
),
color: color,
),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
playSound(color: Colors.purple, colorNumber: 1),
playSound(color: Colors.indigo, colorNumber: 2),
playSound(color: Colors.blue, colorNumber: 3),
playSound(color: Colors.green, colorNumber: 4),
playSound(color: Colors.yellow, colorNumber: 5),
playSound(color: Colors.orange, colorNumber: 6),
playSound(color: Colors.red, colorNumber: 7),
],
),
),
),
),
);
}
}