Я использую плагин флаттера аудиоплееры: ^ 0.7.8, приведенный ниже код работает в Android, но не работает в IOS.Я запускаю код в реальном устройстве IOS и нажимаю кнопку.Предполагается, что воспроизведение файла mp3, но нет звука вообще.Пожалуйста, помогите решить эту проблему.
Я уже настроил info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Здесь с распечаткой из консоли:
- флаттер:загрузка завершена, uri = file: ///var/mobile/Containers/Data/Application/E3A576E2-0F21-44CF-AF99-319D539767D0/Library/Caches/demo.mp3
- Синхронизация файлов на устройстве iPhone ...
- трепетание: _platformCallHandler вызывает audio.onCurrentPosition {playerId: 273e1d27-b6e8-4516-bb3f-967a41dff308, значение: 0}
- трепетание: _platformCallHandler вызывать audio.eed: 271d6: b1-4516-bb3f-967a41dff308, значение: AVPlayerItemStatus.failed}
Здесь с моим кодом:
class _MyHomePageState extends State<MyHomePage> {
AudioPlayer audioPlugin = AudioPlayer();
String mp3Uri;
@override
void initState() {
AudioPlayer.logEnabled = true;
_load();
}
Future<Null> _load() async {
final ByteData data = await rootBundle.load('assets/demo.mp3');
Directory tempDir = await getTemporaryDirectory();
File tempFile = File('${tempDir.path}/demo.mp3');
await tempFile.writeAsBytes(data.buffer.asUint8List(), flush: true);
mp3Uri = tempFile.uri.toString();
print('finished loading, uri=$mp3Uri');
}
void _playSound() {
if (mp3Uri != null) {
audioPlugin.play(mp3Uri, isLocal: true,
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Audio Player Demo Home Page'),
),
body: Center(),
floatingActionButton: FloatingActionButton(
onPressed: _playSound,
tooltip: 'Play',
child: const Icon(Icons.play_arrow),
),
);
}
}