Reason Pun

增加了播放录制音频的逻辑

...@@ -103,7 +103,7 @@ class _PoemRecordAudioPageState extends State<PoemRecordAudioPage> { ...@@ -103,7 +103,7 @@ class _PoemRecordAudioPageState extends State<PoemRecordAudioPage> {
103 margin: EdgeInsets.symmetric( 103 margin: EdgeInsets.symmetric(
104 vertical: 20.px, horizontal: 20.px), 104 vertical: 20.px, horizontal: 20.px),
105 height: MediaQuery.of(context).size.height - 105 height: MediaQuery.of(context).size.height -
106 - 100.px - 106 + 150.px -
107 widget.poemPanelHeight, 107 widget.poemPanelHeight,
108 width: double.infinity, 108 width: double.infinity,
109 decoration: BoxDecoration( 109 decoration: BoxDecoration(
...@@ -166,7 +166,7 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -166,7 +166,7 @@ class _AudioToolBarState extends State<AudioToolBar> {
166 int currentTimer = 0; 166 int currentTimer = 0;
167 int duration = 10 * 1000; //TODO 60 * 1000; 167 int duration = 10 * 1000; //TODO 60 * 1000;
168 168
169 - Codec _codec = Codec.aacMP4; 169 + Codec _codec = Codec.aacMP4; //TODO why accMP4?
170 String _mPath = 'tau_file.mp4'; 170 String _mPath = 'tau_file.mp4';
171 FlutterSoundPlayer? _mPlayer = FlutterSoundPlayer(); 171 FlutterSoundPlayer? _mPlayer = FlutterSoundPlayer();
172 FlutterSoundRecorder? _mRecorder = FlutterSoundRecorder(); 172 FlutterSoundRecorder? _mRecorder = FlutterSoundRecorder();
...@@ -175,6 +175,7 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -175,6 +175,7 @@ class _AudioToolBarState extends State<AudioToolBar> {
175 bool _mPlaybackReady = false; 175 bool _mPlaybackReady = false;
176 bool _mRecorderIsRecording = false; 176 bool _mRecorderIsRecording = false;
177 bool _mRecorderIsPaused = false; 177 bool _mRecorderIsPaused = false;
178 + bool _mPlayerIsPlaying = false;
178 179
179 @override 180 @override
180 void initState() { 181 void initState() {
...@@ -246,7 +247,7 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -246,7 +247,7 @@ class _AudioToolBarState extends State<AudioToolBar> {
246 _timer 247 _timer
247 ..reset() 248 ..reset()
248 ..start(); 249 ..start();
249 - _mRecorderIsRecording = true; 250 +
250 _mRecorder! 251 _mRecorder!
251 .startRecorder( 252 .startRecorder(
252 toFile: _mPath, 253 toFile: _mPath,
...@@ -254,7 +255,10 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -254,7 +255,10 @@ class _AudioToolBarState extends State<AudioToolBar> {
254 audioSource: theSource, 255 audioSource: theSource,
255 ) 256 )
256 .then((value) { 257 .then((value) {
257 - setState(() {}); 258 + setState(() {
259 + _mPlaybackReady = false;
260 + _mRecorderIsRecording = true;
261 + });
258 }); 262 });
259 } 263 }
260 } 264 }
...@@ -262,9 +266,10 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -262,9 +266,10 @@ class _AudioToolBarState extends State<AudioToolBar> {
262 void pauseRecorder() async { 266 void pauseRecorder() async {
263 if (_mRecorderIsInited && _mPlayer!.isStopped) { 267 if (_mRecorderIsInited && _mPlayer!.isStopped) {
264 _timer.pause(); 268 _timer.pause();
265 - _mRecorderIsPaused = true;
266 await _mRecorder!.pauseRecorder().then((value) { 269 await _mRecorder!.pauseRecorder().then((value) {
267 - setState(() {}); 270 + setState(() {
271 + _mRecorderIsPaused = true;
272 + });
268 }); 273 });
269 } 274 }
270 } 275 }
...@@ -273,21 +278,20 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -273,21 +278,20 @@ class _AudioToolBarState extends State<AudioToolBar> {
273 if (_mRecorderIsInited && _mPlayer!.isStopped) { 278 if (_mRecorderIsInited && _mPlayer!.isStopped) {
274 _timer.start(); 279 _timer.start();
275 await _mRecorder!.resumeRecorder().then((value) { 280 await _mRecorder!.resumeRecorder().then((value) {
281 + setState(() {
276 _mRecorderIsPaused = false; 282 _mRecorderIsPaused = false;
277 - setState(() {}); 283 + });
278 }); 284 });
279 } 285 }
280 } 286 }
281 287
282 void stopRecorder() async { 288 void stopRecorder() async {
283 if (_mRecorderIsInited && _mPlayer!.isStopped) { 289 if (_mRecorderIsInited && _mPlayer!.isStopped) {
284 - print("### stop record");
285 -
286 _timer.pause(); 290 _timer.pause();
287 await _mRecorder!.stopRecorder().then((value) { 291 await _mRecorder!.stopRecorder().then((value) {
288 - _mRecorderIsRecording = false;
289 setState(() { 292 setState(() {
290 _mPlaybackReady = true; 293 _mPlaybackReady = true;
294 + _mRecorderIsRecording = false;
291 }); 295 });
292 }); 296 });
293 } 297 }
...@@ -299,10 +303,14 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -299,10 +303,14 @@ class _AudioToolBarState extends State<AudioToolBar> {
299 .startPlayer( 303 .startPlayer(
300 fromURI: _mPath, 304 fromURI: _mPath,
301 whenFinished: () { 305 whenFinished: () {
302 - setState(() {}); 306 + setState(() {
307 + _mPlayerIsPlaying = false;
308 + });
303 }) 309 })
304 .then((value) { 310 .then((value) {
305 - setState(() {}); 311 + setState(() {
312 + _mPlayerIsPlaying = true;
313 + });
306 }); 314 });
307 } 315 }
308 } 316 }
...@@ -324,7 +332,79 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -324,7 +332,79 @@ class _AudioToolBarState extends State<AudioToolBar> {
324 16.px, 332 16.px,
325 8.px, 333 8.px,
326 ), 334 ),
327 - child: Row( 335 + child: _mPlaybackReady
336 + ? Row(
337 + mainAxisAlignment: MainAxisAlignment.spaceBetween,
338 + crossAxisAlignment: CrossAxisAlignment.end,
339 + children: [
340 + InkWell(
341 + onTap: () {
342 + _mPlaybackReady = false;
343 + setState(() {});
344 + },
345 + child: Stack(
346 + alignment: Alignment.center,
347 + children: [
348 + Icon(
349 + Icons.circle,
350 + color: Colors.black38,
351 + size: 60.px,
352 + ),
353 + Icon(
354 + Icons.edit,
355 + color: Colors.white,
356 + size: 30.px,
357 + ),
358 + ],
359 + ),
360 + ),
361 + InkWell(
362 + onTap: () {
363 + _mPlayerIsPlaying ? stopPlayer() : play();
364 + },
365 + child: Stack(
366 + alignment: Alignment.center,
367 + children: [
368 + Icon(
369 + Icons.circle,
370 + color: Colors.white,
371 + size: 80.px,
372 + ),
373 + Icon(
374 + _mPlayerIsPlaying ? Icons.pause : Icons.play_arrow,
375 + color: Colors.red,
376 + size: 65.px,
377 + ),
378 + ],
379 + ),
380 + ),
381 + InkWell(
382 + onTap: () {
383 + NavigatorUtils.push(
384 + context,
385 + '${PoemRouter.poemPublish}?data=100',
386 + clearStack: true,
387 + );
388 + },
389 + child: Stack(
390 + alignment: Alignment.center,
391 + children: [
392 + Icon(
393 + Icons.circle,
394 + color: Colors.black38,
395 + size: 60.px,
396 + ),
397 + Icon(
398 + Icons.navigate_next_outlined,
399 + color: Colors.white,
400 + size: 30.px,
401 + ),
402 + ],
403 + ),
404 + ),
405 + ],
406 + )
407 + : Row(
328 mainAxisAlignment: MainAxisAlignment.spaceBetween, 408 mainAxisAlignment: MainAxisAlignment.spaceBetween,
329 crossAxisAlignment: CrossAxisAlignment.end, 409 crossAxisAlignment: CrossAxisAlignment.end,
330 children: [ 410 children: [
...@@ -413,24 +493,10 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -413,24 +493,10 @@ class _AudioToolBarState extends State<AudioToolBar> {
413 ], 493 ],
414 ), 494 ),
415 ), 495 ),
416 - InkWell( 496 + SizedBox(
417 - onTap: () {}, 497 + height: 10.px,
418 - child: Stack( 498 + width: 60.px,
419 - alignment: Alignment.center, 499 + )
420 - children: [
421 - Icon(
422 - Icons.circle,
423 - color: Colors.black38,
424 - size: 60.px,
425 - ),
426 - Icon(
427 - Icons.arrow_right_alt,
428 - color: Colors.white,
429 - size: 30.px,
430 - ),
431 - ],
432 - ),
433 - ),
434 ], 500 ],
435 ), 501 ),
436 ); 502 );
......