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) {
276 - _mRecorderIsPaused = false; 281 + setState(() {
277 - setState(() {}); 282 + _mRecorderIsPaused = false;
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,115 +332,173 @@ class _AudioToolBarState extends State<AudioToolBar> { ...@@ -324,115 +332,173 @@ 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
328 - mainAxisAlignment: MainAxisAlignment.spaceBetween, 336 + ? Row(
329 - crossAxisAlignment: CrossAxisAlignment.end, 337 + mainAxisAlignment: MainAxisAlignment.spaceBetween,
330 - children: [ 338 + crossAxisAlignment: CrossAxisAlignment.end,
331 - InkWell(
332 - onTap: () {
333 - if (_mRecorderIsRecording) {
334 - _mRecorderIsPaused ? resumeRecorder() : pauseRecorder();
335 - } else {
336 - NavigatorUtils.push(
337 - context,
338 - '${PoemRouter.poemRecordVideoPage}?id=100',
339 - );
340 - }
341 - },
342 - child: Stack(
343 - alignment: Alignment.center,
344 children: [ 339 children: [
345 - Icon( 340 + InkWell(
346 - Icons.circle, 341 + onTap: () {
347 - color: Colors.black38, 342 + _mPlaybackReady = false;
348 - size: 60.px, 343 + setState(() {});
349 - ), 344 + },
350 - _mRecorderIsRecording 345 + child: Stack(
351 - ? _mRecorderIsPaused 346 + alignment: Alignment.center,
352 - ? Icon( 347 + children: [
353 - Icons.play_arrow, 348 + Icon(
354 - color: Colors.white, 349 + Icons.circle,
355 - size: 30.px, 350 + color: Colors.black38,
356 - ) 351 + size: 60.px,
357 - : Icon( 352 + ),
358 - Icons.pause, 353 + Icon(
359 - color: Colors.white, 354 + Icons.edit,
360 - size: 30.px,
361 - )
362 - : Icon(
363 - Icons.camera_alt_outlined,
364 color: Colors.white, 355 color: Colors.white,
365 size: 30.px, 356 size: 30.px,
366 ), 357 ),
367 - ], 358 + ],
368 - ), 359 + ),
369 - ),
370 - InkWell(
371 - onTap: () {
372 - _mRecorderIsRecording ? stopRecorder() : record();
373 - },
374 - child: Stack(
375 - alignment: Alignment.center,
376 - children: [
377 - Icon(
378 - Icons.circle,
379 - color: Colors.white,
380 - size: 80.px,
381 ), 360 ),
382 - _mRecorderIsRecording 361 + InkWell(
383 - ? SizedBox( 362 + onTap: () {
384 - width: 60.px, 363 + _mPlayerIsPlaying ? stopPlayer() : play();
385 - height: 60.px, 364 + },
386 - child: CircularProgressIndicator( 365 + child: Stack(
387 - strokeWidth: 5.px, 366 + alignment: Alignment.center,
388 - value: currentTimer / duration, 367 + children: [
389 - ), 368 + Icon(
390 - ) 369 + Icons.circle,
391 - : Container(), 370 + color: Colors.white,
392 - Icon( 371 + size: 80.px,
393 - Icons.circle, 372 + ),
394 - color: Colors.red, 373 + Icon(
395 - size: 65.px, 374 + _mPlayerIsPlaying ? Icons.pause : Icons.play_arrow,
375 + color: Colors.red,
376 + size: 65.px,
377 + ),
378 + ],
379 + ),
396 ), 380 ),
397 - _mRecorderIsRecording 381 + InkWell(
398 - ? Container() 382 + onTap: () {
399 - : Text( 383 + NavigatorUtils.push(
400 - "60s", 384 + context,
401 - style: TextStyle( 385 + '${PoemRouter.poemPublish}?data=100',
402 - fontSize: 12.px, 386 + clearStack: true,
403 - color: Colors.white, 387 + );
404 - ), 388 + },
389 + child: Stack(
390 + alignment: Alignment.center,
391 + children: [
392 + Icon(
393 + Icons.circle,
394 + color: Colors.black38,
395 + size: 60.px,
405 ), 396 ),
406 - _mRecorderIsRecording 397 + Icon(
407 - ? Icon( 398 + Icons.navigate_next_outlined,
408 - Icons.stop_rounded,
409 color: Colors.white, 399 color: Colors.white,
410 - size: 32.px, 400 + size: 30.px,
411 - ) 401 + ),
412 - : Container(), 402 + ],
403 + ),
404 + ),
413 ], 405 ],
414 - ), 406 + )
415 - ), 407 + : Row(
416 - InkWell( 408 + mainAxisAlignment: MainAxisAlignment.spaceBetween,
417 - onTap: () {}, 409 + crossAxisAlignment: CrossAxisAlignment.end,
418 - child: Stack(
419 - alignment: Alignment.center,
420 children: [ 410 children: [
421 - Icon( 411 + InkWell(
422 - Icons.circle, 412 + onTap: () {
423 - color: Colors.black38, 413 + if (_mRecorderIsRecording) {
424 - size: 60.px, 414 + _mRecorderIsPaused ? resumeRecorder() : pauseRecorder();
415 + } else {
416 + NavigatorUtils.push(
417 + context,
418 + '${PoemRouter.poemRecordVideoPage}?id=100',
419 + );
420 + }
421 + },
422 + child: Stack(
423 + alignment: Alignment.center,
424 + children: [
425 + Icon(
426 + Icons.circle,
427 + color: Colors.black38,
428 + size: 60.px,
429 + ),
430 + _mRecorderIsRecording
431 + ? _mRecorderIsPaused
432 + ? Icon(
433 + Icons.play_arrow,
434 + color: Colors.white,
435 + size: 30.px,
436 + )
437 + : Icon(
438 + Icons.pause,
439 + color: Colors.white,
440 + size: 30.px,
441 + )
442 + : Icon(
443 + Icons.camera_alt_outlined,
444 + color: Colors.white,
445 + size: 30.px,
446 + ),
447 + ],
448 + ),
425 ), 449 ),
426 - Icon( 450 + InkWell(
427 - Icons.arrow_right_alt, 451 + onTap: () {
428 - color: Colors.white, 452 + _mRecorderIsRecording ? stopRecorder() : record();
429 - size: 30.px, 453 + },
454 + child: Stack(
455 + alignment: Alignment.center,
456 + children: [
457 + Icon(
458 + Icons.circle,
459 + color: Colors.white,
460 + size: 80.px,
461 + ),
462 + _mRecorderIsRecording
463 + ? SizedBox(
464 + width: 60.px,
465 + height: 60.px,
466 + child: CircularProgressIndicator(
467 + strokeWidth: 5.px,
468 + value: currentTimer / duration,
469 + ),
470 + )
471 + : Container(),
472 + Icon(
473 + Icons.circle,
474 + color: Colors.red,
475 + size: 65.px,
476 + ),
477 + _mRecorderIsRecording
478 + ? Container()
479 + : Text(
480 + "60s",
481 + style: TextStyle(
482 + fontSize: 12.px,
483 + color: Colors.white,
484 + ),
485 + ),
486 + _mRecorderIsRecording
487 + ? Icon(
488 + Icons.stop_rounded,
489 + color: Colors.white,
490 + size: 32.px,
491 + )
492 + : Container(),
493 + ],
494 + ),
430 ), 495 ),
496 + SizedBox(
497 + height: 10.px,
498 + width: 60.px,
499 + )
431 ], 500 ],
432 ), 501 ),
433 - ),
434 - ],
435 - ),
436 ); 502 );
437 } 503 }
438 } 504 }
......