我从https://pub.dartlang.org/导入了一个名为 audioplayers 的包。我在 .yaml 文件依赖项中添加了依赖项:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
audioplayers: ^0.15.1
assets:
- assets/
note1.wav 是我在 assets 文件夹中的音频文件。
然后我flutter pub get
在终端中运行命令。
下面是我的颤振代码:
import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: FlatButton(
onPressed: () {
final player = AudioCache();
player.play('note1.wav');
},
child: Text('click me'),
),
),
),
),
);
}
}
但是没有声音,而是我收到以下错误:
iOS => call startHeadlessService, playerId e24a78e3-1f9f-439a-8f55-c4a55386da4b
iOS => call play, playerId e24a78e3-1f9f-439a-8f55-c4a55386da4b
play!
isLocal: 1 1
volume: 1.000000 1
position: 0 (null)
setUrl /Users/pratteekshaurya/Library/Developer/CoreSimulator/Devices/13364636-6425-40FF-A7EC-9C2498EFA847/data/Containers/Data/Application/B2C9DBA6-8B70-4D3B-9463-5754D4556893/Library/Caches/note1.wav
player status: 1
iOS -> updateDuration...3.750000
iOS -> invokechannel
iOS -> onSoundComplete...
flutter: Fatal Error: Callback lookup failed!
我是新来的,我无法弄清楚问题是什么,因为我遵循了文档中给出的确切信息。