Commit 46c68b4593dd6106ccecf0c6f7ecad1d461c4ab1

Authored by 吴启风
1 parent 0596f520

feat:翻页取消先声评测&增加先声取消回调

android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/methodChannels/SingSoungMethodChannel.kt
@@ -94,4 +94,10 @@ class SingSoungMethodChannel(activity: FlutterActivity, flutterEngine: FlutterEn @@ -94,4 +94,10 @@ class SingSoungMethodChannel(activity: FlutterActivity, flutterEngine: FlutterEn
94 invokeMethod("voiceEnd", null) 94 invokeMethod("voiceEnd", null)
95 } 95 }
96 } 96 }
  97 +
  98 + override fun onCancel() {
  99 + GlobalHandler.runOnMainThread {
  100 + invokeMethod("voiceCancel", null)
  101 + }
  102 + }
97 } 103 }
98 \ No newline at end of file 104 \ No newline at end of file
lib/pages/reading/bloc/reading_bloc.dart
@@ -139,10 +139,10 @@ class ReadingPageBloc @@ -139,10 +139,10 @@ class ReadingPageBloc
139 return; 139 return;
140 } 140 }
141 141
142 - if (call.method == 'voiceEnd') {  
143 - //评测结束 142 + if (call.method == 'voiceEnd' || call.method == 'voiceCancel') {
  143 + //评测结束or评测取消
144 if (kDebugMode) { 144 if (kDebugMode) {
145 - print('评测结束'); 145 + print(call.method == 'voiceEnd' ? '评测结束' : '评测取消');
146 } 146 }
147 _isRecording = false; 147 _isRecording = false;
148 add(OnXSVoiceStateChangeEvent()); 148 add(OnXSVoiceStateChangeEvent());
@@ -151,6 +151,7 @@ class ReadingPageBloc @@ -151,6 +151,7 @@ class ReadingPageBloc
151 151
152 if (call.method == 'voiceFail') { 152 if (call.method == 'voiceFail') {
153 //评测失败 153 //评测失败
  154 + _isRecording = false;
154 EasyLoading.showToast('评测失败'); 155 EasyLoading.showToast('评测失败');
155 return; 156 return;
156 } 157 }
@@ -179,9 +180,8 @@ class ReadingPageBloc @@ -179,9 +180,8 @@ class ReadingPageBloc
179 void _pageControllerChange(CurrentPageIndexChangeEvent event, 180 void _pageControllerChange(CurrentPageIndexChangeEvent event,
180 Emitter<ReadingPageState> emitter) async { 181 Emitter<ReadingPageState> emitter) async {
181 _currentPage = event.pageIndex; 182 _currentPage = event.pageIndex;
182 - debugPrint("WQF _playOriginalAudioInner begin"); 183 + _voiceXsCancel();
183 _playOriginalAudioInner(null); 184 _playOriginalAudioInner(null);
184 - debugPrint("WQF _playOriginalAudioInner end");  
185 emitter(CurrentPageIndexState()); 185 emitter(CurrentPageIndexState());
186 } 186 }
187 187
@@ -229,7 +229,7 @@ class ReadingPageBloc @@ -229,7 +229,7 @@ class ReadingPageBloc
229 await audioPlayer.stop(); 229 await audioPlayer.stop();
230 } else { 230 } else {
231 _isOriginAudioPlaying = true; 231 _isOriginAudioPlaying = true;
232 - debugPrint("WQF _playOriginalAudioInner _isOriginAudioPlaying: true"); 232 + Log.d("_playOriginalAudioInner _isOriginAudioPlaying: true");
233 audioUrl ??= currentPageData()?.audioUrl ?? ''; 233 audioUrl ??= currentPageData()?.audioUrl ?? '';
234 _playAudio(audioUrl); 234 _playAudio(audioUrl);
235 } 235 }
@@ -355,7 +355,10 @@ class ReadingPageBloc @@ -355,7 +355,10 @@ class ReadingPageBloc
355 355
356 ///取消评测(用于处理退出页面后录音未停止等异常情况的保护操作) 356 ///取消评测(用于处理退出页面后录音未停止等异常情况的保护操作)
357 void _voiceXsCancel() { 357 void _voiceXsCancel() {
358 - methodChannel.invokeMethod('cancelVoice'); 358 + Log.d("取消评测 _voiceXsCancel _isRecording=$_isRecording");
  359 + if (_isRecording) {
  360 + methodChannel.invokeMethod('cancelVoice');
  361 + }
359 } 362 }
360 363
361 void _voicePlayStateChange(VoicePlayStateChangeEvent event, 364 void _voicePlayStateChange(VoicePlayStateChangeEvent event,