Reason Pun

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

......@@ -103,7 +103,7 @@ class _PoemRecordAudioPageState extends State<PoemRecordAudioPage> {
margin: EdgeInsets.symmetric(
vertical: 20.px, horizontal: 20.px),
height: MediaQuery.of(context).size.height -
100.px -
150.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,
)
],
),
);
......