Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OnePoem
/
OnePoem-App
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Reason Pun
2022-01-26 22:37:10 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1956b48f9ec21856311c7e1384d5f1e02329ea35
1956b48f
1 parent
53d45ce2
增加了播放录制音频的逻辑
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
31 deletions
lib/poem/page/poem_record_audio.dart
lib/poem/page/poem_record_audio.dart
View file @
1956b48
...
...
@@ -103,7 +103,7 @@ class _PoemRecordAudioPageState extends State<PoemRecordAudioPage> {
margin:
EdgeInsets
.
symmetric
(
vertical:
20
.
px
,
horizontal:
20
.
px
),
height:
MediaQuery
.
of
(
context
).
size
.
height
-
1
0
0
.
px
-
1
5
0
.
px
-
widget
.
poemPanelHeight
,
width:
double
.
infinity
,
decoration:
BoxDecoration
(
...
...
@@ -166,7 +166,7 @@ class _AudioToolBarState extends State<AudioToolBar> {
int
currentTimer
=
0
;
int
duration
=
10
*
1000
;
//TODO 60 * 1000;
Codec
_codec
=
Codec
.
aacMP4
;
Codec
_codec
=
Codec
.
aacMP4
;
//TODO why accMP4?
String
_mPath
=
'tau_file.mp4'
;
FlutterSoundPlayer
?
_mPlayer
=
FlutterSoundPlayer
();
FlutterSoundRecorder
?
_mRecorder
=
FlutterSoundRecorder
();
...
...
@@ -175,6 +175,7 @@ class _AudioToolBarState extends State<AudioToolBar> {
bool
_mPlaybackReady
=
false
;
bool
_mRecorderIsRecording
=
false
;
bool
_mRecorderIsPaused
=
false
;
bool
_mPlayerIsPlaying
=
false
;
@override
void
initState
()
{
...
...
@@ -246,7 +247,7 @@ class _AudioToolBarState extends State<AudioToolBar> {
_timer
..
reset
()
..
start
();
_mRecorderIsRecording
=
true
;
_mRecorder
!
.
startRecorder
(
toFile:
_mPath
,
...
...
@@ -254,7 +255,10 @@ class _AudioToolBarState extends State<AudioToolBar> {
audioSource:
theSource
,
)
.
then
((
value
)
{
setState
(()
{});
setState
(()
{
_mPlaybackReady
=
false
;
_mRecorderIsRecording
=
true
;
});
});
}
}
...
...
@@ -262,9 +266,10 @@ class _AudioToolBarState extends State<AudioToolBar> {
void
pauseRecorder
()
async
{
if
(
_mRecorderIsInited
&&
_mPlayer
!.
isStopped
)
{
_timer
.
pause
();
_mRecorderIsPaused
=
true
;
await
_mRecorder
!.
pauseRecorder
().
then
((
value
)
{
setState
(()
{});
setState
(()
{
_mRecorderIsPaused
=
true
;
});
});
}
}
...
...
@@ -273,21 +278,20 @@ class _AudioToolBarState extends State<AudioToolBar> {
if
(
_mRecorderIsInited
&&
_mPlayer
!.
isStopped
)
{
_timer
.
start
();
await
_mRecorder
!.
resumeRecorder
().
then
((
value
)
{
setState
(()
{
_mRecorderIsPaused
=
false
;
setState
(()
{
});
});
});
}
}
void
stopRecorder
()
async
{
if
(
_mRecorderIsInited
&&
_mPlayer
!.
isStopped
)
{
print
(
"### stop record"
);
_timer
.
pause
();
await
_mRecorder
!.
stopRecorder
().
then
((
value
)
{
_mRecorderIsRecording
=
false
;
setState
(()
{
_mPlaybackReady
=
true
;
_mRecorderIsRecording
=
false
;
});
});
}
...
...
@@ -299,10 +303,14 @@ class _AudioToolBarState extends State<AudioToolBar> {
.
startPlayer
(
fromURI:
_mPath
,
whenFinished:
()
{
setState
(()
{});
setState
(()
{
_mPlayerIsPlaying
=
false
;
});
})
.
then
((
value
)
{
setState
(()
{});
setState
(()
{
_mPlayerIsPlaying
=
true
;
});
});
}
}
...
...
@@ -324,7 +332,79 @@ class _AudioToolBarState extends State<AudioToolBar> {
16
.
px
,
8
.
px
,
),
child:
Row
(
child:
_mPlaybackReady
?
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
crossAxisAlignment:
CrossAxisAlignment
.
end
,
children:
[
InkWell
(
onTap:
()
{
_mPlaybackReady
=
false
;
setState
(()
{});
},
child:
Stack
(
alignment:
Alignment
.
center
,
children:
[
Icon
(
Icons
.
circle
,
color:
Colors
.
black38
,
size:
60
.
px
,
),
Icon
(
Icons
.
edit
,
color:
Colors
.
white
,
size:
30
.
px
,
),
],
),
),
InkWell
(
onTap:
()
{
_mPlayerIsPlaying
?
stopPlayer
()
:
play
();
},
child:
Stack
(
alignment:
Alignment
.
center
,
children:
[
Icon
(
Icons
.
circle
,
color:
Colors
.
white
,
size:
80
.
px
,
),
Icon
(
_mPlayerIsPlaying
?
Icons
.
pause
:
Icons
.
play_arrow
,
color:
Colors
.
red
,
size:
65
.
px
,
),
],
),
),
InkWell
(
onTap:
()
{
NavigatorUtils
.
push
(
context
,
'
${PoemRouter.poemPublish}
?data=100'
,
clearStack:
true
,
);
},
child:
Stack
(
alignment:
Alignment
.
center
,
children:
[
Icon
(
Icons
.
circle
,
color:
Colors
.
black38
,
size:
60
.
px
,
),
Icon
(
Icons
.
navigate_next_outlined
,
color:
Colors
.
white
,
size:
30
.
px
,
),
],
),
),
],
)
:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
crossAxisAlignment:
CrossAxisAlignment
.
end
,
children:
[
...
...
@@ -413,24 +493,10 @@ class _AudioToolBarState extends State<AudioToolBar> {
],
),
),
InkWell
(
onTap:
()
{},
child:
Stack
(
alignment:
Alignment
.
center
,
children:
[
Icon
(
Icons
.
circle
,
color:
Colors
.
black38
,
size:
60
.
px
,
),
Icon
(
Icons
.
arrow_right_alt
,
color:
Colors
.
white
,
size:
30
.
px
,
),
],
),
),
SizedBox
(
height:
10
.
px
,
width:
60
.
px
,
)
],
),
);
...
...
Please
register
or
login
to post a comment