我使用音频播放器在Flutter中收听广播频道(流式传输)。它在后台运行良好,除非用户收到呼叫。在这种情况下,播放会停止,但不会在通话结束时自动重新开始。
AudioPlayer audioPlayer = new AudioPlayer();
const kUrl = "http://5.39.71.159:8865/stream";
Future play() async {
int result = await audioPlayer.play(kUrl);
setState(() {
playerState = PlayerState.playing;
});
}
Future stop() async {
int result = await audioPlayer.stop();
}
当有电话打进来时,如何将收音机置于暂停模式并在电话结束时重新开始播放?
答案 0 :(得分:0)
尝试一下
audioPlayer.onPlayerStateChanged.listen((AudioPlayerState s) => {
print('Current player state: $s');
setState(() => palyerState = s);
});