【发布时间】:2020-11-15 00:22:44
【问题描述】:
我正在使用flutter插件audioplayers: ^0.15.1,下面的代码在Android中工作,但在IOS中不工作,而不是冻结应用程序。
我在 ios 模拟器中运行代码并单击按钮。它假设播放 mp3 文件,但根本没有声音。应用程序被冻结。 assets_audio_player 插件也有同样的问题。
请帮忙解决这个问题。
import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
void playNote(int noteNO) {
final player = AudioCache();
player.play('note$noteNO.wav');
}
Expanded buildKey(int no, Color color) {
return Expanded(
child: FlatButton(
color: color,
onPressed: () {
playNote(no);
},
),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
buildKey(1,Colors.red),
buildKey(2,Colors.orange),
buildKey(3,Colors.yellow),
buildKey(4,Colors.green),
buildKey(5,Colors.blue),
buildKey(6,Colors.indigo),
buildKey(7,Colors.purple),
],
),
),
),
),
);
}
}
void playNote(int noteNO) {
final player = AudioCache();
player.play('note$noteNO.wav');
}
调试控制台:Screenshot
iOS => call startHeadlessService, playerId 6178a81e-22dc-485b-bfc8-f6a8402f518e
iOS => call play, playerId 6178a81e-22dc-485b-bfc8-f6a8402f518e
play!
isLocal: 1 1
volume: 1.000000 1
position: 0 (null)
setUrl /Users/akshay/Library/Developer/CoreSimulator/Devices/575F03D0-0EBE-4813-970A-14128CEF49ED/data/Containers/Data/Application/394C51F0-1ABD-4315-921A-F92E97CC1F98/Library/Caches/note5.wav
[VERBOSE-2:profiler_metrics_ios.mm(184)] Error retrieving thread information: (ipc/send) invalid destination port
player status: 2
player status: 2
player status: 2
【问题讨论】:
标签: ios flutter audio plugins ios-simulator