Commit 7d6a6ddc0fc405397b02703745154d0e84a8595b
1 parent
e3f2bf59
feat:1.0.1优化
Showing
6 changed files
with
87 additions
and
56 deletions
lib/pages/repeatafter/widgets/repeat_after_item.dart
@@ -20,9 +20,10 @@ class RepeatAfterItem extends StatelessWidget { | @@ -20,9 +20,10 @@ class RepeatAfterItem extends StatelessWidget { | ||
20 | child: GestureDetector( | 20 | child: GestureDetector( |
21 | onTap: (){ | 21 | onTap: (){ |
22 | if (entity != null) { | 22 | if (entity != null) { |
23 | - if (!entity!.lock!) { | ||
24 | - tapEvent?.call(); | ||
25 | - } | 23 | + // if (!entity!.lock!) { |
24 | + // tapEvent?.call(); | ||
25 | + // } | ||
26 | + tapEvent?.call(); | ||
26 | } | 27 | } |
27 | }, | 28 | }, |
28 | child: Stack( | 29 | child: Stack( |
lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart
@@ -69,6 +69,7 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo | @@ -69,6 +69,7 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo | ||
69 | RepeatAfterContentBloc(this.courseLessonId) : super(RepeatAfterContentInitial()) { | 69 | RepeatAfterContentBloc(this.courseLessonId) : super(RepeatAfterContentInitial()) { |
70 | on<VoiceRecordStateChangeEvent>(_voiceRecordStateChange); | 70 | on<VoiceRecordStateChangeEvent>(_voiceRecordStateChange); |
71 | on<PostFollowReadContentEvent>(_postFollowReadContent); | 71 | on<PostFollowReadContentEvent>(_postFollowReadContent); |
72 | + on<ChangeVideoPlayIndexEvent>(_changeVideoPlayIndex); | ||
72 | on<VideoPlayChangeEvent>(_videoPlayStateChange); | 73 | on<VideoPlayChangeEvent>(_videoPlayStateChange); |
73 | on<RecordeVoicePlayEvent>(_recordeVoicePlay); | 74 | on<RecordeVoicePlayEvent>(_recordeVoicePlay); |
74 | on<XSVoiceResultEvent>(_voiceXsResult); | 75 | on<XSVoiceResultEvent>(_voiceXsResult); |
@@ -207,4 +208,10 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo | @@ -207,4 +208,10 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo | ||
207 | assert(event.audioUrl.isNotEmpty); | 208 | assert(event.audioUrl.isNotEmpty); |
208 | await audioPlayer.play(UrlSource(event.audioUrl)); | 209 | await audioPlayer.play(UrlSource(event.audioUrl)); |
209 | } | 210 | } |
211 | + | ||
212 | + | ||
213 | + ///更改播放的视频 | ||
214 | + void _changeVideoPlayIndex(ChangeVideoPlayIndexEvent event,Emitter<RepeatAfterContentState> emitter) async { | ||
215 | + emitter(ChangeVideoPlayIndexState(event.isNext)); | ||
216 | + } | ||
210 | } | 217 | } |
lib/pages/repeataftercontent/bloc/repeat_after_content_event.dart
@@ -46,4 +46,9 @@ class RecordeVoicePlayEvent extends RepeatAfterContentEvent { | @@ -46,4 +46,9 @@ class RecordeVoicePlayEvent extends RepeatAfterContentEvent { | ||
46 | 46 | ||
47 | class PostFollowReadContentEvent extends RepeatAfterContentEvent {} | 47 | class PostFollowReadContentEvent extends RepeatAfterContentEvent {} |
48 | 48 | ||
49 | +class ChangeVideoPlayIndexEvent extends RepeatAfterContentEvent { | ||
50 | + final bool isNext; | ||
51 | + ChangeVideoPlayIndexEvent(this.isNext); | ||
52 | +} | ||
53 | + | ||
49 | 54 |
lib/pages/repeataftercontent/bloc/repeat_after_content_state.dart
@@ -14,3 +14,8 @@ class VoiceRecordStateChange extends RepeatAfterContentState {} | @@ -14,3 +14,8 @@ class VoiceRecordStateChange extends RepeatAfterContentState {} | ||
14 | class RequestDataState extends RepeatAfterContentState {} | 14 | class RequestDataState extends RepeatAfterContentState {} |
15 | 15 | ||
16 | class XSVoiceTestState extends RepeatAfterContentState {} | 16 | class XSVoiceTestState extends RepeatAfterContentState {} |
17 | + | ||
18 | +class ChangeVideoPlayIndexState extends RepeatAfterContentState { | ||
19 | + final bool isNext; | ||
20 | + ChangeVideoPlayIndexState(this.isNext); | ||
21 | +} |
lib/pages/repeataftercontent/repeat_after_content_page.dart
@@ -79,7 +79,7 @@ class _RepeatAfterContentPage extends StatelessWidget { | @@ -79,7 +79,7 @@ class _RepeatAfterContentPage extends StatelessWidget { | ||
79 | fit: BoxFit.fill | 79 | fit: BoxFit.fill |
80 | ), | 80 | ), |
81 | ), | 81 | ), |
82 | - child: videoUrl.isEmpty?Container(): RepeatVideoWidget(videoUrl: bloc.entityList?.first?.videoUrl,), | 82 | + child: videoUrl.isEmpty?Container(): RepeatVideoWidget(videoUrl: bloc.entityList?.first?.videoUrl,videoUrls: bloc.entityList??[],), |
83 | ), | 83 | ), |
84 | ), | 84 | ), |
85 | ///右侧操作区 | 85 | ///右侧操作区 |
@@ -157,38 +157,30 @@ class _RepeatAfterContentPage extends StatelessWidget { | @@ -157,38 +157,30 @@ class _RepeatAfterContentPage extends StatelessWidget { | ||
157 | children: [ | 157 | children: [ |
158 | Row( | 158 | Row( |
159 | children: [ | 159 | children: [ |
160 | - SizedBox( | ||
161 | - height: 23.h, | ||
162 | - width: 33.w, | 160 | + IconButton( |
161 | + onPressed: () => bloc.add(ChangeVideoPlayIndexEvent(false)), | ||
162 | + icon: Image.asset( | ||
163 | + 'previous'.assetPng, | ||
164 | + height: 23.h, | ||
165 | + width: 23.w, | ||
166 | + ) | ||
163 | ), | 167 | ), |
164 | - // IconButton( | ||
165 | - // onPressed: (){}, | ||
166 | - // icon: Image.asset( | ||
167 | - // 'previous'.assetPng, | ||
168 | - // height: 23.h, | ||
169 | - // width: 23.w, | ||
170 | - // ) | ||
171 | - // ), | ||
172 | IconButton( | 168 | IconButton( |
173 | onPressed:() => bloc.add(VideoPlayChangeEvent()), | 169 | onPressed:() => bloc.add(VideoPlayChangeEvent()), |
174 | icon: Image.asset( | 170 | icon: Image.asset( |
175 | 'video_pause'.assetPng, | 171 | 'video_pause'.assetPng, |
176 | height: 50.h, | 172 | height: 50.h, |
177 | - width: 50.w, | 173 | + width: 50.h, |
178 | ) | 174 | ) |
179 | ), | 175 | ), |
180 | - SizedBox( | ||
181 | - height: 23.h, | ||
182 | - width: 23.w, | ||
183 | - ), | ||
184 | - // IconButton( | ||
185 | - // onPressed: (){}, | ||
186 | - // icon: Image.asset( | ||
187 | - // 'next'.assetPng, | ||
188 | - // height: 23.h, | ||
189 | - // width: 23.w, | ||
190 | - // ) | ||
191 | - // ) | 176 | + IconButton( |
177 | + onPressed: () => bloc.add(ChangeVideoPlayIndexEvent(true)), | ||
178 | + icon: Image.asset( | ||
179 | + 'next'.assetPng, | ||
180 | + height: 23.h, | ||
181 | + width: 23.w, | ||
182 | + ) | ||
183 | + ) | ||
192 | ], | 184 | ], |
193 | ), | 185 | ), |
194 | Row( | 186 | Row( |
lib/pages/repeataftercontent/widgets/repeat_video_widget.dart
@@ -2,12 +2,14 @@ import 'package:flutter/material.dart'; | @@ -2,12 +2,14 @@ import 'package:flutter/material.dart'; | ||
2 | import 'package:flutter_bloc/flutter_bloc.dart'; | 2 | import 'package:flutter_bloc/flutter_bloc.dart'; |
3 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 3 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
4 | import 'package:video_player/video_player.dart'; | 4 | import 'package:video_player/video_player.dart'; |
5 | +import 'package:wow_english/models/read_content_entity.dart'; | ||
5 | 6 | ||
6 | import '../bloc/repeat_after_content_bloc.dart'; | 7 | import '../bloc/repeat_after_content_bloc.dart'; |
7 | 8 | ||
8 | class RepeatVideoWidget extends StatefulWidget { | 9 | class RepeatVideoWidget extends StatefulWidget { |
9 | - const RepeatVideoWidget({super.key, this.videoUrl}); | 10 | + const RepeatVideoWidget({super.key, this.videoUrl, required this.videoUrls}); |
10 | final String? videoUrl; | 11 | final String? videoUrl; |
12 | + final List<ReadContentEntity?> videoUrls; | ||
11 | 13 | ||
12 | @override | 14 | @override |
13 | State<StatefulWidget> createState() { | 15 | State<StatefulWidget> createState() { |
@@ -20,6 +22,7 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | @@ -20,6 +22,7 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | ||
20 | String _currentTime = '00:00'; | 22 | String _currentTime = '00:00'; |
21 | String _totalTime = '00:00'; | 23 | String _totalTime = '00:00'; |
22 | double _playDegree = 0.5; | 24 | double _playDegree = 0.5; |
25 | + int _currentPlayIndex = 0; | ||
23 | 26 | ||
24 | String formatDuration(Duration duration) { | 27 | String formatDuration(Duration duration) { |
25 | String minutes = duration.inMinutes.remainder(60).toString().padLeft(2, '0'); | 28 | String minutes = duration.inMinutes.remainder(60).toString().padLeft(2, '0'); |
@@ -52,17 +55,11 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | @@ -52,17 +55,11 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | ||
52 | @override | 55 | @override |
53 | void initState() { | 56 | void initState() { |
54 | super.initState(); | 57 | super.initState(); |
55 | - _controller = VideoPlayerController.network(widget.videoUrl??'') | ||
56 | - ..initialize().then((_){ | ||
57 | - setState(() { | ||
58 | - _currentTime = formatDuration(_controller!.value.position); | ||
59 | - _totalTime = formatDuration(_controller!.value.duration); | ||
60 | - _controller!.setLooping(true); | ||
61 | - _controller!.setVolume(100); | ||
62 | - _controller!.play(); | ||
63 | - }); | ||
64 | - _addListener(); | ||
65 | - }); | 58 | + var videoUrl = ''; |
59 | + if(widget.videoUrls.isNotEmpty) { | ||
60 | + videoUrl = widget.videoUrls[_currentPlayIndex]?.videoUrl??''; | ||
61 | + } | ||
62 | + _initVideo(videoUrl); | ||
66 | } | 63 | } |
67 | 64 | ||
68 | @override | 65 | @override |
@@ -77,6 +74,22 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | @@ -77,6 +74,22 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | ||
77 | _controller!.pause(); | 74 | _controller!.pause(); |
78 | } | 75 | } |
79 | } | 76 | } |
77 | + | ||
78 | + if (state is ChangeVideoPlayIndexState) { | ||
79 | + if(state.isNext) { | ||
80 | + if (_currentPlayIndex != (widget.videoUrls.length-1)) { | ||
81 | + _currentPlayIndex++; | ||
82 | + _destroyVideo(); | ||
83 | + _initVideo(widget.videoUrls[_currentPlayIndex]!.videoUrl!); | ||
84 | + } | ||
85 | + } else { | ||
86 | + if (_currentPlayIndex > 0) { | ||
87 | + _currentPlayIndex--; | ||
88 | + _destroyVideo(); | ||
89 | + _initVideo(widget.videoUrls[_currentPlayIndex]!.videoUrl!); | ||
90 | + } | ||
91 | + } | ||
92 | + } | ||
80 | }, | 93 | }, |
81 | child: SizedBox( | 94 | child: SizedBox( |
82 | child: Column( | 95 | child: Column( |
@@ -105,20 +118,10 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | @@ -105,20 +118,10 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | ||
105 | left: 0, | 118 | left: 0, |
106 | right: 0, | 119 | right: 0, |
107 | bottom: 0, | 120 | bottom: 0, |
108 | - child: Slider( | ||
109 | - min:0, | ||
110 | - max: 1.0, | ||
111 | - activeColor: const Color(0xFF78B72D), | ||
112 | - inactiveColor: const Color(0xFF7E756C), | ||
113 | - onChangeStart: (value) { | ||
114 | - | ||
115 | - }, | ||
116 | - onChangeEnd: (value) { | ||
117 | - | ||
118 | - }, | ||
119 | - onChanged: (value) { | ||
120 | - | ||
121 | - }, value: _playDegree, | 121 | + child: LinearProgressIndicator( |
122 | + color: const Color(0xFF78B72D), | ||
123 | + backgroundColor: const Color(0xFF7E756C), | ||
124 | + value: _playDegree, | ||
122 | )) | 125 | )) |
123 | ], | 126 | ], |
124 | ), | 127 | ), |
@@ -148,10 +151,28 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | @@ -148,10 +151,28 @@ class _RepeatVideoWidgetState extends State<RepeatVideoWidget> { | ||
148 | ); | 151 | ); |
149 | } | 152 | } |
150 | 153 | ||
151 | - @override | ||
152 | - void dispose() { | 154 | + void _initVideo(String videoUrl) { |
155 | + _controller = VideoPlayerController.network(widget.videoUrl??'') | ||
156 | + ..initialize().then((_){ | ||
157 | + setState(() { | ||
158 | + _currentTime = formatDuration(_controller!.value.position); | ||
159 | + _totalTime = formatDuration(_controller!.value.duration); | ||
160 | + _controller!.setLooping(false); | ||
161 | + _controller!.setVolume(100); | ||
162 | + _controller!.play(); | ||
163 | + }); | ||
164 | + _addListener(); | ||
165 | + }); | ||
166 | + } | ||
167 | + | ||
168 | + void _destroyVideo() { | ||
153 | _controller?.dispose(); | 169 | _controller?.dispose(); |
154 | _controller?.removeListener(() {}); | 170 | _controller?.removeListener(() {}); |
171 | + } | ||
172 | + | ||
173 | + @override | ||
174 | + void dispose() { | ||
175 | + _destroyVideo(); | ||
155 | super.dispose(); | 176 | super.dispose(); |
156 | } | 177 | } |
157 | } | 178 | } |
158 | \ No newline at end of file | 179 | \ No newline at end of file |