当前位置:网站首页>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
边栏推荐
- Shell script learning notes - regular expressions
- Codeforces Round #784 (Div. 4) (A - H)题解
- Solve the problem that PowerShell mining occupies 100% of cpu7 in win7
- tf. keras. layers. Density function
- Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (7)
- [software testing] understand the basic knowledge of software testing
- Opencv reads webcam video and saves it locally
- Microservices (distributed architecture)
- Redis data server / database / cache (2022)
- Airtrack cracking wireless network password (Dictionary running method)
猜你喜欢
Solve the problem that PowerShell mining occupies 100% of cpu7 in win7
Depth deterministic strategy gradient (ddpg)
Error installing Mongo service 'mongodb server' on win10 failed to start
It turns out that PID was born in the struggle between Lao wangtou and Lao sky
Q-Learning & Sarsa
Linux Redis——Redis 数据库缓存服务
ele之Table表格的封装
Detailed explanation of distributed things
Processes and threads
Kubernetes study notes
随机推荐
The problem of removing spaces from strings
How to count the number of all files in a directory under win10 system
Jz76 delete duplicate nodes in linked list
The shell monitors the depth of the IBM MQ queue and scans it three times in 10s. When the depth value exceeds 5 for more than two times, the queue name and depth value are output.
Windows MySQL 8 zip installation
[if you want to do a good job, you must first use its tools] Guide for downloading and using paper editing and document management (endnote, latex, jabref, overflow) resources
Codeforces round 784 (Div. 4) (a - H)
Niuke white moon race 6 [solution]
The difference between encodeuri and encodeuricomponent
When using art template inheritance, compileerror: invalid or unexpected token generated
First knowledge of C language ~ branch statements
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
Codeforces Round #784 (Div. 4) (A - H)题解
Redis Cluster集群,主节点故障,主从切换后ip变化,客户端需要处理不
Winsock programming interface experiment: Ping
MySQL function syntax
MySQL insert free column
HLS / chisel uses CORDIC hyperbolic system to realize square root calculation
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (10)
tf. keras. layers. Embedding function