Commit e79583ae75ddcd5cd581c298beafd6067e0b08ab
1 parent
e39984d8
feat:修复先声录音对音频会话的类别和模式设置影响了音频输出,导致单通道出声(听筒)
Showing
2 changed files
with
7 additions
and
2 deletions
lib/pages/reading/bloc/reading_bloc.dart
| ... | ... | @@ -130,6 +130,7 @@ class ReadingPageBloc | 
| 130 | 130 | "setMethodCallHandler method=${call.method} arguments=${call.arguments}"); | 
| 131 | 131 | if (call.method == 'voiceResult') { | 
| 132 | 132 | //评测结果 | 
| 133 | + await audioPlayer.setAudioContext(AudioContext()); | |
| 133 | 134 | await audioPlayer.setBalance(0.0); | 
| 134 | 135 | add(XSVoiceResultEvent(call.arguments)); | 
| 135 | 136 | return; | 
| ... | ... | @@ -151,6 +152,7 @@ class ReadingPageBloc | 
| 151 | 152 | print(call.method == 'voiceEnd' ? '评测结束' : '评测取消'); | 
| 152 | 153 | } | 
| 153 | 154 | _isRecording = false; | 
| 155 | + await audioPlayer.setAudioContext(AudioContext()); | |
| 154 | 156 | await audioPlayer.setBalance(0.0); | 
| 155 | 157 | add(OnXSVoiceStateChangeEvent()); | 
| 156 | 158 | return; | 
| ... | ... | @@ -159,6 +161,7 @@ class ReadingPageBloc | 
| 159 | 161 | if (call.method == 'voiceFail') { | 
| 160 | 162 | //评测失败 | 
| 161 | 163 | _isRecording = false; | 
| 164 | + await audioPlayer.setAudioContext(AudioContext()); | |
| 162 | 165 | await audioPlayer.setBalance(0.0); | 
| 163 | 166 | EasyLoading.showToast('评测失败'); | 
| 164 | 167 | return; | 
| ... | ... | @@ -279,7 +282,9 @@ class ReadingPageBloc | 
| 279 | 282 | |
| 280 | 283 | Future<void> _playAudio(String? audioUrl) async { | 
| 281 | 284 | if (audioUrl!.isNotEmpty) { | 
| 282 | - await audioPlayer.play(UrlSource(audioUrl)); | |
| 285 | + await audioPlayer.play(UrlSource(audioUrl), | |
| 286 | + balance: 0.0, ctx: AudioContext() | |
| 287 | + ); | |
| 283 | 288 | } | 
| 284 | 289 | } | 
| 285 | 290 | ... | ... | 
pubspec.yaml
| ... | ... | @@ -95,7 +95,7 @@ dependencies: | 
| 95 | 95 | # UI适配 https://pub.dev/packages/responsive_framework | 
| 96 | 96 | responsive_framework: ^1.0.0 | 
| 97 | 97 | # 音频播放 https://pub.dev/packages/audioplayers | 
| 98 | - audioplayers: ^4.1.0 | |
| 98 | + audioplayers: ^6.0.0 | |
| 99 | 99 | # 语音录制 https://pub.dev/packages/flutter_sound | 
| 100 | 100 | flutter_sound: ^9.2.13 | 
| 101 | 101 | # 音频播放 https://pub.dev/packages/audio_session | ... | ... | 
