提交 b44d2924 authored 作者: yueweilu's avatar yueweilu

添加笔记时 语音可以播放

上级 d99e0482
...@@ -81,6 +81,8 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide ...@@ -81,6 +81,8 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
late TextEditingController searchInput = TextEditingController(); late TextEditingController searchInput = TextEditingController();
just_audio.AudioPlayer audioPlayer = just_audio.AudioPlayer();
///------------------------------------------ 页面 生命周期-------------------------------------------------------- ///------------------------------------------ 页面 生命周期--------------------------------------------------------
...@@ -316,7 +318,6 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide ...@@ -316,7 +318,6 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
} }
// 停止录音 // 停止录音
void stopRecorder() async{ void stopRecorder() async{
just_audio.AudioPlayer audioPlayer = just_audio.AudioPlayer();
startRecording = false; startRecording = false;
final path = await _mRecorder.stopRecorder(); final path = await _mRecorder.stopRecorder();
var duration = await audioPlayer.setFilePath(path!); var duration = await audioPlayer.setFilePath(path!);
...@@ -354,6 +355,27 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide ...@@ -354,6 +355,27 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
clearDiscussAudios(); clearDiscussAudios();
} }
// 播放音频
void playAudio(AudioModel audioModel){
if(audioPlayer.playerState.playing){
audioPlayer.stop();
audioModel.currentDuration = '0:00:00';
// if(currentPlayMediaModel.id == mediaModel.id){
// return;
// }
}
// 本地音频
audioPlayer.setFilePath(audioModel.path);
audioPlayer.play();
audioPlayer.positionStream.listen((position) {
String temp = Tools.formatDuration(position);
Console.log('播放时间---------------------$temp');
audioModel.currentDuration = temp;
update();
});
// currentPlayMediaModel = mediaModel;
}
// 添加讨论图片 // 添加讨论图片
void addDiscussInputImages(String path){ void addDiscussInputImages(String path){
discussInputImages.add(path); discussInputImages.add(path);
...@@ -874,4 +896,5 @@ class AudioModel { ...@@ -874,4 +896,5 @@ class AudioModel {
AudioModel({required this.path, required this.duration}); AudioModel({required this.path, required this.duration});
String path; String path;
String duration; String duration;
late String currentDuration;
} }
...@@ -61,7 +61,7 @@ class _ReadCategoryPageState extends State<ReadCategoryPage> { ...@@ -61,7 +61,7 @@ class _ReadCategoryPageState extends State<ReadCategoryPage> {
child: CustomInputSearch( child: CustomInputSearch(
controller: widget.controller.searchInput, controller: widget.controller.searchInput,
readOnly: false, readOnly: false,
hintText: '搜索全文---目录', hintText: '搜索全文',
onTap: () { onTap: () {
// context.pushNamed(Routes.msgs); // context.pushNamed(Routes.msgs);
}, },
......
...@@ -62,7 +62,7 @@ class _ReadDiscussPageState extends State<ReadDiscussPage> { ...@@ -62,7 +62,7 @@ class _ReadDiscussPageState extends State<ReadDiscussPage> {
child: CustomInputSearch( child: CustomInputSearch(
controller: controller.searchInput, controller: controller.searchInput,
readOnly: false, readOnly: false,
hintText: '搜索全文---讨论', hintText: '搜索全文',
onTap: () { onTap: () {
// context.pushNamed(Routes.msgs); // context.pushNamed(Routes.msgs);
}, },
......
...@@ -125,23 +125,29 @@ class _ReadInputDiscussState extends State<ReadInputDiscuss> { ...@@ -125,23 +125,29 @@ class _ReadInputDiscussState extends State<ReadInputDiscuss> {
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
itemBuilder: (BuildContext context, int index){ itemBuilder: (BuildContext context, int index){
return Container( AudioModel audioModel= widget.controller.discussInputAudios[index];
height: 20.w, return GestureDetector(
margin: EdgeInsets.only(right: 130.w), onTap: (){
widget.controller.playAudio(audioModel);
},
child: Container( child: Container(
margin: EdgeInsets.only(top: 5.w), height: 20.w,
padding: EdgeInsets.only(right:20.w,left: 10.w), margin: EdgeInsets.only(right: 130.w),
decoration: BoxDecoration( child: Container(
borderRadius: BorderRadius.circular(10.w), margin: EdgeInsets.only(top: 5.w),
color: Colours.cF9, padding: EdgeInsets.only(right:20.w,left: 10.w),
), decoration: BoxDecoration(
child: Row( borderRadius: BorderRadius.circular(10.w),
// mainAxisSize: MainAxisSize.min, color: Colours.cF9,
mainAxisAlignment:MainAxisAlignment.spaceBetween, ),
children: [ child: Row(
Image.asset('assets/images/audio.png'), // mainAxisSize: MainAxisSize.min,
// Text('0:00/1:52',style: TextStyle(fontSize: 10.w,height: 1.4,color: Colours.c9),) mainAxisAlignment:MainAxisAlignment.spaceBetween,
], children: [
Image.asset('assets/images/audio.png'),
// Text('0:00/1:52',style: TextStyle(fontSize: 10.w,height: 1.4,color: Colours.c9),)
],
),
), ),
), ),
); );
......
...@@ -60,7 +60,7 @@ class _ReadNotePageState extends State<ReadNotePage> { ...@@ -60,7 +60,7 @@ class _ReadNotePageState extends State<ReadNotePage> {
child: CustomInputSearch( child: CustomInputSearch(
controller: controller.searchInput, controller: controller.searchInput,
readOnly: false, readOnly: false,
hintText: '搜索全文---笔记', hintText: '搜索全文',
onTap: () { onTap: () {
// context.pushNamed(Routes.msgs); // context.pushNamed(Routes.msgs);
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论