Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
book-app
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
book-app
Commits
36fab99c
提交
36fab99c
authored
2月 05, 2024
作者:
yueweilu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
音频录制
上级
47ead385
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
91 行增加
和
7 行删除
+91
-7
stop.png
assets/images/2.0x/stop.png
+0
-0
stop.png
assets/images/3.0x/stop.png
+0
-0
stop.png
assets/images/stop.png
+0
-0
controller.dart
lib/pages/read_web/controller.dart
+71
-5
index.dart
lib/pages/read_web/index.dart
+7
-1
input_discuss.dart
lib/pages/read_web/widgets/input_discuss.dart
+7
-1
access.dart
lib/utils/access.dart
+6
-0
没有找到文件。
assets/images/2.0x/stop.png
0 → 100644
浏览文件 @
36fab99c
974 Bytes
assets/images/3.0x/stop.png
0 → 100644
浏览文件 @
36fab99c
1.8 KB
assets/images/stop.png
0 → 100644
浏览文件 @
36fab99c
500 Bytes
lib/pages/read_web/controller.dart
浏览文件 @
36fab99c
...
...
@@ -38,18 +38,23 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
List
<
String
>
discussInputImages
=
[];
// 讨论添加的语音path数组
List
<
String
>
discussInputAudios
=
[];
// 笔记标题
String
noteTitle
=
''
;
bool
_show
=
true
;
bool
get
show
=>
_show
;
// 录音
final
FlutterSoundRecorder
_mRecorder
=
FlutterSoundRecorder
();
// 录音开始
bool
startRecording
=
false
;
///------------------------------------------ 页面 生命周期--------------------------------------------------------
@override
void
onInit
()
{
discussTitleFocusNode
.
addListener
(
_onCommentFocusChanged
);
openTheRecorder
();
super
.
onInit
();
}
...
...
@@ -78,6 +83,65 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
update
();
}
// 初始化录音组件
Future
<
void
>
openTheRecorder
()
async
{
// 获取权限
if
(
await
Access
.
microphone
()){
await
_mRecorder
.
openRecorder
();
final
session
=
await
AudioSession
.
instance
;
await
session
.
configure
(
AudioSessionConfiguration
(
avAudioSessionCategory:
AVAudioSessionCategory
.
playAndRecord
,
avAudioSessionCategoryOptions:
AVAudioSessionCategoryOptions
.
allowBluetooth
|
AVAudioSessionCategoryOptions
.
defaultToSpeaker
,
avAudioSessionMode:
AVAudioSessionMode
.
spokenAudio
,
avAudioSessionRouteSharingPolicy:
AVAudioSessionRouteSharingPolicy
.
defaultPolicy
,
avAudioSessionSetActiveOptions:
AVAudioSessionSetActiveOptions
.
none
,
androidAudioAttributes:
const
AndroidAudioAttributes
(
contentType:
AndroidAudioContentType
.
speech
,
flags:
AndroidAudioFlags
.
none
,
usage:
AndroidAudioUsage
.
voiceCommunication
,
),
androidAudioFocusGainType:
AndroidAudioFocusGainType
.
gain
,
androidWillPauseWhenDucked:
true
,
));
}
// 没有权限
else
{
}
}
// 开启录音
void
record
()
async
{
startRecording
=
true
;
String
filePath
=
await
_getDocumentsDirectory
();
_mRecorder
.
startRecorder
(
toFile:
'
$filePath
/tau_file.mp4'
,
audioSource:
AudioSource
.
microphone
,
codec:
Codec
.
aacMP4
,
);
_mRecorder
?.
setSubscriptionDuration
(
Duration
(
milliseconds:
100
));
_mRecorder
?.
onProgress
?.
listen
((
e
)
{
var
date
=
DateTime
.
fromMillisecondsSinceEpoch
(
e
.
duration
.
inMilliseconds
,
isUtc:
true
);
var
text
=
DateFormat
(
'mm:ss:'
).
format
(
date
);
print
(
'--------------
$text
'
);
});
update
();
}
// 停止录音
void
stopRecorder
()
async
{
startRecording
=
false
;
_mRecorder
.
stopRecorder
().
then
((
value
){
print
(
'------value-------------------
$value
---------------------------------------'
);
});
update
();
}
// 添加讨论图片
void
addDiscussInputImages
(
String
path
){
discussInputImages
.
add
(
path
);
...
...
@@ -321,10 +385,12 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
}
//获取存储目录
Future
<
String
>
_getDocumentsDirectory
()
async
{
final
directory
=
await
get
ApplicationDocuments
Directory
();
return
directory
.
path
;
final
directory
=
await
get
ExternalStorage
Directory
();
return
directory
!
.
path
;
}
///------------------------------------------ app 生命周期--------------------------------------------------------
...
...
@@ -368,4 +434,5 @@ class ToolModel {
bool
selected
;
String
icon
;
String
activeIcon
;
}
\ No newline at end of file
}
lib/pages/read_web/index.dart
浏览文件 @
36fab99c
...
...
@@ -3,16 +3,22 @@ library web;
import
'dart:convert'
;
import
'package:audio_session/audio_session.dart'
;
import
'package:easy_refresh/easy_refresh.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_book/theme.dart'
;
import
'package:flutter_inappwebview/flutter_inappwebview.dart'
;
import
'package:flutter_book/utils/index.dart'
;
import
'package:flutter_screenutil/flutter_screenutil.dart'
;
import
'package:flutter_sound/public/flutter_sound_recorder.dart'
;
import
'package:flutter_sound_platform_interface/flutter_sound_platform_interface.dart'
;
import
'package:flutter_sound_platform_interface/flutter_sound_recorder_platform_interface.dart'
;
import
'package:get/get.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:intl/intl.dart'
;
import
'package:path_provider/path_provider.dart'
;
import
'dart:async'
;
import
'package:plugin_platform_interface/plugin_platform_interface.dart'
;
import
'../../apis/index.dart'
;
import
'../../models/index.dart'
;
...
...
lib/pages/read_web/widgets/input_discuss.dart
浏览文件 @
36fab99c
...
...
@@ -174,9 +174,15 @@ class _ReadInputDiscussState extends State<ReadInputDiscuss> {
Gaps
.
hGaps10
,
GestureDetector
(
onTap:
()
async
{
if
(
widget
.
controller
.
startRecording
){
widget
.
controller
.
stopRecorder
();
}
else
{
widget
.
controller
.
record
();
}
},
child:
Image
.
asset
(
'assets/images/read_add_audio.png'
)
child:
Image
.
asset
(
widget
.
controller
.
startRecording
?
'assets/images/stop.png'
:
'assets/images/read_add_audio.png'
)
),
widget
.
controller
.
chatType
==
0
?
const
SizedBox
():
GestureDetector
(
onTap:
(){
...
...
lib/utils/access.dart
浏览文件 @
36fab99c
...
...
@@ -31,4 +31,10 @@ abstract class Access {
return
result
[
Permission
.
storage
]
==
PermissionStatus
.
granted
;
}
/// 获取麦克风权限
static
Future
<
bool
>
microphone
()
async
{
final
result
=
await
[
Permission
.
microphone
].
request
();
return
result
[
Permission
.
microphone
]
==
PermissionStatus
.
granted
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论