当前位置:网站首页>Xamarin效果第二十二篇之录音效果
Xamarin效果第二十二篇之录音效果
2022-04-23 03:02:00 【dotNET跨平台】
在前面文章中简单玩了玩GIS的基本操作、Mark相关、AR、测距、加载三维白模和可扩展浮动操作;今天抽空再来分享一下录音效果;啥也不说了都在效果里
:
1、首次尝试了开源的Plugin.AudioRecorder结果发现没效果,也可能是我的姿势不对
:
https://github.com/NateRickard/Plugin.AudioRecorder
2、请教大佬大白,送了一句:“反转依赖",然后贴了点代码;我是没听明白什么是反转依赖,最终才知道是使用DependencyService这个类;
说白了就是共享代码可以调用每一个独立平台的原生API
3、共享代码定义要实现的接口:

4、然后每个平台实现接口,屌丝机下:

5、注册平台实现,这样Xamarin.Forms才可以在运行时找到它们

6、安卓下录音就用MediaRecorder
//设置麦克风
mMediaRecorder.SetAudioSource(AudioSource.Mic);
mMediaRecorder.SetOutputFormat(OutputFormat.Default);
mMediaRecorder.SetAudioEncoder(AudioEncoder.Default);
mMediaRecorder.SetOutputFile(filePath);
mMediaRecorder.Prepare();
mMediaRecorder.Start();
7、播放录音效果
public void Play(RecordModel model)
{
if(model != null)
{
var player = new MediaPlayer();
player.Prepared += (s, e) =>
{
player.Start();
model.IsPlaying = true;
};
player.SetDataSource(model.Path);
player.Prepare();
//播放完成时
player.Completion += (ss, ee) =>
{
model.IsPlaying = false;
};
}
}
8、前台所有录音文件还是CollectionView(独爱),他的ItemTemplate:
<Grid HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="50">
<StackLayout Orientation="Horizontal" Margin="10,4,0,0" Padding="0">
<!--小话筒-->
<Label Text="" FontSize="22" BackgroundColor="Transparent" FontFamily="iconfont.ttf#" VerticalOptions="Center" TextColor="{Binding IsPlaying,Converter={StaticResource IsPlayingToTextColorConverter}}" />
<!--录音保存的名称-->
<Label Text="{Binding Name}" VerticalOptions="Center" FontSize="18" TextColor="{Binding IsPlaying,Converter={StaticResource IsPlayingToTextColorConverter}}" />
<!--时长,这里主要StringFormat用法-->
<Label Text="{Binding Duration,StringFormat='{0}秒'}" Margin="10,0,0,0" VerticalOptions="Center" FontSize="18" TextColor="{Binding IsPlaying,Converter={StaticResource IsPlayingToTextColorConverter}}" />
<!--播放-->
<Label Text="" FontSize="25" VerticalOptions="Center" FontFamily="iconfont.ttf#" TextColor="#98A6B1">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type vm:MainViewModel}},Path=PlayRecordCommand}" CommandParameter="{Binding}" /> </Label.GestureRecognizers>
</Label>
</StackLayout>
</Grid>
最终简单的效果先这样吧
;以后有时间的话,可以再去摸索一下更复杂的效果
;编程不息、Bug不止、无Bug、无生活
;改bug的冷静、编码的激情、完成后的喜悦、挖坑的激动 、填坑的兴奋;这也许就是屌丝程序员的乐趣吧;今天就到这里吧;希望自己有动力一步一步坚持下去;生命不息,代码不止;大家抽空可以看看今天分享的效果,有好的意见和想法,可以在留言板随意留言;我看到后会第一时间回复大家,多谢大家的一直默默的关注和支持!如果觉得不错,那就伸出您的小手点个赞并关注一下,多谢您的支持!
版权声明
本文为[dotNET跨平台]所创,转载请带上原文链接,感谢
https://blog.csdn.net/sd7o95o/article/details/124357646
边栏推荐
- Niuke white moon race 5 [problem solving mathematics field]
- Dynamic sequence table + OJ
- Step principle of logical regression in machine learning
- What is the difference between varchar and char?
- tf. keras. layers. Inputlayer function
- Practical combat of industrial defect detection project (II) -- steel surface defect detection based on deep learning framework yolov5
- Winsock programming interface experiment: Ping
- Some problems encountered in setting Django pure interface, channel and MySQL on the pagoda panel
- Linux Redis ——Redis HA Sentinel 集群搭建详解 & Redis主从部署
- Shell script learning notes -- shell operation on files sed
猜你喜欢

REINFORCE

How to build an integrated industrial Internet plus hazardous safety production management platform?

tf. keras. layers. Conv? D function

树莓派开发笔记(十二):入手研华ADVANTECH工控树莓派UNO-220套件(一):介绍和运行系统

L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)

Kubernetes - Introduction to actual combat

Encapsulation of ele table

How to write the expected salary on your resume to double your salary during the interview?

The interface request takes too long. Jstack observes the lock holding

tf. keras. layers. Density function
随机推荐
Shell script learning -- practical case
FileNotFoundError: [Errno 2] No such file or directory
leangoo脑图-共享式多人协作思维导图工具分享
B blocks of the 46th ICPC Asian regional competition (Kunming)
Huawei machine test question -- deformation of hj53 Yang Hui triangle
Gavl021, gavl281, AC220V to 5v200ma small volume non isolated chip scheme
OCR recognition PDF file
Classification and regression tree of machine learning
Guangcheng cloud service can fill in a daily report regularly every day
ele之Table表格的封装
Airtrack cracking wireless network password (Dictionary running method)
The express project changes the jade template to art template
VirtualBox virtual machine (Oracle VM)
树莓派开发笔记(十二):入手研华ADVANTECH工控树莓派UNO-220套件(一):介绍和运行系统
《信息系统项目管理师总结》第四章 项目成本管理
Learn regular expression options, assertions
HLS / chisel uses CORDIC hyperbolic system to realize square root calculation
Plug in for vscode
Processes and threads
Introduction to ACM [inclusion exclusion theorem]