Android原生项目中涉及到录屏相关的内容(MediaProjectionManager),就尝试写了Forms版本的录屏功能,系统要求Android 5.0+,iOS 9.0+。
iOS录屏实现
iOS下实现录屏比较简单,通过RPScreenRecorder.SharedRecorder.StartRecording
方法调用iOS9.0中加入的录屏功能。

首次调用录屏会提示用户是否允许录屏,用户允许后接下来的8分钟都不会再提示。

调用RPScreenRecorder.SharedRecorder.StopRecording
停止录屏,录屏结束后可以通过RPPreviewViewController
来预览录制的视频内容,也可以调用RPScreenRecorder.SharedRecorder.DiscardRecording
丢弃录制的视频。

结束录屏后的预览界面:

预览界面点击Cancel或者Save都会调用iOS中RPPreviewViewControllerDelegate
委托 的两个DidFinish
方法。点击Cancel操作调用DidFinish(RPPreviewViewController previewController)
方法,保存和分享操作调用重载方法DidFinish(RPPreviewViewController previewController, Foundation.NSSet<Foundation.NSString> activityTypes)
。

Android录屏
原生参考:http://www.truiton.com/2015/05/capture-record-android-screen-using-mediaprojection-apis/
初始化MediaProjectionManager
对象,调用MediaProjectionManager对象的CreateScreenCaptureIntent
方法创建意图,通过StartActivityForResult
方法启动系统提供的录屏功能。

屏蔽麦克风声音没有实现
在Activity的OnActivityResult
方法中接收录屏数据。

Android项目中通过继承DialogFragment
自定义了两个Dialog,PromptDialog
和PreviewDialog
,PromptDialog用来确认用户的操作,是否放弃以录制视频。PreviewDialog模仿iOS端实现的视频预览,以达到相似的用户体验。


目前已知的问题是VideoView被Toolbar遮挡,布局无效。MediaController播放控制不能显示。
项目地址:https://github.com/MyueX/ScreenRecorder
获取最新咨询请关注公众号:XamarinTop或扫描如下二维码

网友评论