From 6b0947ca40abfc92245504b958cccc6af9e6b574 Mon Sep 17 00:00:00 2001 From: wuqifeng <540416539@qq.com> Date: Sun, 9 Jul 2023 12:23:29 +0800 Subject: [PATCH] feat:绘本增加initVoiceSdk(ios需要);页面销毁时取消先声评测 --- android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/methodChannels/SingSoungMethodChannel.kt | 6 +++--- lib/pages/practice/bloc/topic_picture_bloc.dart | 6 ++++++ lib/pages/reading/bloc/reading_bloc.dart | 6 ++++++ lib/pages/reading/reading_page.dart | 11 ++++++++++- lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart | 6 ++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/methodChannels/SingSoungMethodChannel.kt b/android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/methodChannels/SingSoungMethodChannel.kt index 76d1f11..78d945f 100644 --- a/android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/methodChannels/SingSoungMethodChannel.kt +++ b/android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/methodChannels/SingSoungMethodChannel.kt @@ -44,22 +44,22 @@ class SingSoungMethodChannel(activity: FlutterActivity, flutterEngine: FlutterEn } "startVoice" -> { val paramMap = call.arguments as HashMap - Log.d(TAG, "SingSoungMethodChannel startVoice=${call.arguments.javaClass} paramMap=$paramMap") paramMap["word"]?.let { SingEngineHelper.startRecord(it) } } "stopVoice" -> { - Log.d(TAG, "SingSoungMethodChannel stopVoice") SingEngineHelper.stopRecord() } "startLocalVoice" -> { val paramMap = call.arguments as HashMap - Log.d(TAG, "SingSoungMethodChannel startLocalVoice=${call.arguments.javaClass} paramMap=$paramMap") paramMap["voicePath"]?.let { voiceFilePath -> paramMap["word"]?.let { evaluateContent -> SingEngineHelper.evaluate(voiceFilePath, evaluateContent) } } } + "cancelVoice" -> { + SingEngineHelper.cancel() + } else -> { result.notImplemented() } diff --git a/lib/pages/practice/bloc/topic_picture_bloc.dart b/lib/pages/practice/bloc/topic_picture_bloc.dart index 4b36b9d..c37e3cd 100644 --- a/lib/pages/practice/bloc/topic_picture_bloc.dart +++ b/lib/pages/practice/bloc/topic_picture_bloc.dart @@ -124,6 +124,7 @@ class TopicPictureBloc extends Bloc { pageController.dispose(); audioPlayer.release(); audioPlayer.dispose(); + _voiceXsCancel(); return super.close(); } @@ -195,6 +196,11 @@ class TopicPictureBloc extends Bloc { methodChannel.invokeMethod('stopVoice'); } + ///取消评测(用于处理退出页面后录音未停止等异常情况的保护操作) + void _voiceXsCancel() { + methodChannel.invokeMethod('cancelVoice'); + } + ///先声评测结果 void _voiceXsResult(XSVoiceResultEvent event,Emitter emitter) async { final Map args = event.message as Map; diff --git a/lib/pages/reading/bloc/reading_bloc.dart b/lib/pages/reading/bloc/reading_bloc.dart index 28e67df..e4f933f 100644 --- a/lib/pages/reading/bloc/reading_bloc.dart +++ b/lib/pages/reading/bloc/reading_bloc.dart @@ -167,6 +167,7 @@ class ReadingPageBloc extends Bloc { pageController.dispose(); audioPlayer.release(); audioPlayer.dispose(); + _voiceXsCancel(); return super.close(); } @@ -322,6 +323,11 @@ class ReadingPageBloc extends Bloc { methodChannel.invokeMethod('stopVoice'); } + ///取消评测(用于处理退出页面后录音未停止等异常情况的保护操作) + void _voiceXsCancel() { + methodChannel.invokeMethod('cancelVoice'); + } + void _voicePlayStateChange(VoicePlayStateChangeEvent event, Emitter emitter) async { emitter(VoicePlayStateChange()); diff --git a/lib/pages/reading/reading_page.dart b/lib/pages/reading/reading_page.dart index dd84ca1..67ab5b8 100644 --- a/lib/pages/reading/reading_page.dart +++ b/lib/pages/reading/reading_page.dart @@ -5,6 +5,7 @@ import 'package:wow_english/common/extension/string_extension.dart'; import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart'; import 'package:wow_english/pages/reading/widgets/reading_dialog_widget.dart'; +import '../../common/core/app_consts.dart'; import '../../common/core/user_util.dart'; import '../../models/course_process_entity.dart'; import '../../utils/log_util.dart'; @@ -20,7 +21,15 @@ class ReadingPage extends StatelessWidget { return BlocProvider( create: (_) => ReadingPageBloc(context, PageController(), courseLessonId ?? '') ..add(InitBlocEvent()) - ..add(RequestDataEvent()), + ..add(RequestDataEvent()) + ..add(XSVoiceInitEvent( + { + 'appKey':AppConsts.xsAppKey, + 'service':AppConsts.xsAppService, + 'secretKey':AppConsts.xsAppSecretKey, + 'userId':UserUtil.getUser()!.id.toString(), + } + )), child: _ReadingPage(), ); } diff --git a/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart b/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart index 7989342..77acfe8 100644 --- a/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart +++ b/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart @@ -100,6 +100,7 @@ class RepeatAfterContentBloc extends Bloc close() { _releaseFlauto(); + _voiceXsCancel(); return super.close(); } @@ -215,6 +216,11 @@ class RepeatAfterContentBloc extends Bloc emitter) async { final Map args = event.message as Map; -- libgit2 0.22.2