Commit 46c68b4593dd6106ccecf0c6f7ecad1d461c4ab1
1 parent
0596f520
feat:翻页取消先声评测&增加先声取消回调
Showing
2 changed files
with
16 additions
and
7 deletions
android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/methodChannels/SingSoungMethodChannel.kt
| ... | ... | @@ -94,4 +94,10 @@ class SingSoungMethodChannel(activity: FlutterActivity, flutterEngine: FlutterEn |
| 94 | 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 | 104 | \ No newline at end of file | ... | ... |
lib/pages/reading/bloc/reading_bloc.dart
| ... | ... | @@ -139,10 +139,10 @@ class ReadingPageBloc |
| 139 | 139 | return; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if (call.method == 'voiceEnd') { | |
| 143 | - //评测结束 | |
| 142 | + if (call.method == 'voiceEnd' || call.method == 'voiceCancel') { | |
| 143 | + //评测结束or评测取消 | |
| 144 | 144 | if (kDebugMode) { |
| 145 | - print('评测结束'); | |
| 145 | + print(call.method == 'voiceEnd' ? '评测结束' : '评测取消'); | |
| 146 | 146 | } |
| 147 | 147 | _isRecording = false; |
| 148 | 148 | add(OnXSVoiceStateChangeEvent()); |
| ... | ... | @@ -151,6 +151,7 @@ class ReadingPageBloc |
| 151 | 151 | |
| 152 | 152 | if (call.method == 'voiceFail') { |
| 153 | 153 | //评测失败 |
| 154 | + _isRecording = false; | |
| 154 | 155 | EasyLoading.showToast('评测失败'); |
| 155 | 156 | return; |
| 156 | 157 | } |
| ... | ... | @@ -179,9 +180,8 @@ class ReadingPageBloc |
| 179 | 180 | void _pageControllerChange(CurrentPageIndexChangeEvent event, |
| 180 | 181 | Emitter<ReadingPageState> emitter) async { |
| 181 | 182 | _currentPage = event.pageIndex; |
| 182 | - debugPrint("WQF _playOriginalAudioInner begin"); | |
| 183 | + _voiceXsCancel(); | |
| 183 | 184 | _playOriginalAudioInner(null); |
| 184 | - debugPrint("WQF _playOriginalAudioInner end"); | |
| 185 | 185 | emitter(CurrentPageIndexState()); |
| 186 | 186 | } |
| 187 | 187 | |
| ... | ... | @@ -229,7 +229,7 @@ class ReadingPageBloc |
| 229 | 229 | await audioPlayer.stop(); |
| 230 | 230 | } else { |
| 231 | 231 | _isOriginAudioPlaying = true; |
| 232 | - debugPrint("WQF _playOriginalAudioInner _isOriginAudioPlaying: true"); | |
| 232 | + Log.d("_playOriginalAudioInner _isOriginAudioPlaying: true"); | |
| 233 | 233 | audioUrl ??= currentPageData()?.audioUrl ?? ''; |
| 234 | 234 | _playAudio(audioUrl); |
| 235 | 235 | } |
| ... | ... | @@ -355,7 +355,10 @@ class ReadingPageBloc |
| 355 | 355 | |
| 356 | 356 | ///取消评测(用于处理退出页面后录音未停止等异常情况的保护操作) |
| 357 | 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 | 364 | void _voicePlayStateChange(VoicePlayStateChangeEvent event, | ... | ... |