EasyPusher实现Android手机屏幕桌面直播,实时推送操作画面,用于手游直播等应用
本文转自EasyDarwin开源团队成员John的博客:http://blog.csdn.net/jyt0551/article/details/52651194
由于Android 5.0提供了捕获当前屏幕画面的SDK,基于该SDK,EasyPusher实现了实时推送手机屏幕画面的功能。经测试,效果很不错,延迟也比较低,画面也比较流畅。该功能可运用到小型会议PPT演示、手游直播等行业。
具体来说,MediaProjection 类可以将当前屏幕画面采集到一个surface里面,而MediaCodec可以从一个surface里面获取视频数据源。我们让MediaProjection投射到MediaCodec创建的Surface,MediaCodec就可以获取到MediaProjection投射的视频了。如图所示:
在这里就不再详细描述代码的实现,主要介绍下两个接口:
VirtualDisplay createVirtualDisplay (String name, int width, int height, int dpi, int flags, Surface surface, VirtualDisplay.Callback callback, Handler handler)
Creates a VirtualDisplay to capture the contents of the screen.Parameters
name String: The name of the virtual display, must be non-empty.
要创建的投射器的名称,非空
width int: The width of the virtual display in pixels. Must be greater than 0.
投射后视频的宽度,这里的宽度就是实际上后面MediaCodec初始化的宽度.
height int: The height of the virtual display in pixels. Must be greater than 0.
投射后视频的高度,这里的宽度就是实际上后面MediaCodec初始化的高度.
dpi int: The density of the virtual display in dpi. Must be greater than 0.
投射器的像素密度,未理解啥意思,我们直接用DisplayMetrics的densityDpi即可.
flags int: A combination of virtual display flags. See DisplayManager for the full list of flags.
我们传
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR|DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC|DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION 即可。
surface Surface: The surface to which the content of the virtual display should be rendered, or null if there is none initially.
投射器要投射到的Surface
callback VirtualDisplay.Callback: Callback to call when the virtual display's state changes, or null if none.
投射器更改后的状态回调,我们这里不需要,传null即可。
handler Handler: The Handler on which the callback should be invoked, or null if the callback should be invoked on the calling thread's main Looper.
回调函数将在该Handler所在的线程调用,我们也不需要,传null即可。
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
createInputSurfaceSurface createInputSurface ()
Requests a Surface to use as the input to an encoder, in place of input buffers. 该接口创建一个作为编码器输入的Surface。
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
然后,将后者得到的Surface作为第6个参数传给前者,前者就可以获取到屏幕数据了~
如下图所示,在VLC访问RTSP地址,即可看到屏幕直播。
EasyPusher项目见:https://github.com/EasyDarwin/EasyPusher
获取更多信息
邮件:support@easydarwin.org
WEB:www.EasyDarwin.org
Copyright © EasyDarwin.org 2012-2016
转载于:https://www.cnblogs.com/babosa/p/9217886.html
EasyPusher实现Android手机屏幕桌面直播,实时推送操作画面,用于手游直播等应用相关推荐
- 最新android 手机型号,Android7.0正式推送 可升级手机型号名单都在这里
描述 自3月份首发Android 7.0预览版之后,谷歌于今日向Nexus设备推送了Android 7.0 Nougat牛轧糖正式版升级. Android 7.0的关键改变包括可在同一个屏幕上运行多个 ...
- android手机功耗优化,安卓统一推送实测:待机功耗降30%
IT之家3月18日消息 据泰尔终端实验室官方微信公众号消息,2020年3月16日,OPPO Find X2 通过"移动终端高性能长连接"测试.经检测,OPPO Find X2手机在 ...
- 手游直播到底难在哪里?
1. 技术是当前手游直播最大的障碍 网络直播的大红海中,游戏直播已杀成血海!然而,其中手游直播却还是未被染色的一片蔚蓝.虽然手游始终处于移动互联网的风口浪尖,但在这波直播大浪潮中我们不难发现,相较于端 ...
- EasyPusher安卓Android手机直播推送之MediaCodec 硬编码H264格式
EasyPusher安卓Android手机直播推送之MediaCodec 硬编码H264格式 最近在研究EasyDarwin的Push库EasyPusher,EasyPusher可以推送H264视频到 ...
- android分辨率选择,安卓Android手机屏幕壁纸分辨率选择技巧
大家先看看对应的壁纸分辨率: 屏幕分辨率为 480×320 的Android手机,对应的壁纸分辨率为:640x480. 屏幕分辨率为 800×480 的Android手机,对应的壁纸分辨率为:960x ...
- android壁纸和手机屏幕之间要怎么对应,安卓Android手机屏幕壁纸分辨率选择技巧...
安卓Android手机屏幕壁纸分辨率选择技巧 现在使用安卓手机的人好多了,一个好的手机壁纸自然是大家的追求,那么要怎么挑选适合自己安卓手机的手机壁纸呢~登博教程小编来教你挑选吧~ 大家先看看对应的壁纸 ...
- android 使用asm.jar将android手机屏幕投影到电脑上
使用asm.jar将Android手机屏幕投影到电脑 有时候可能需要将手机上的一些操作投影出来,比如一些App Demo的展示等.其实,有专门的硬件设备能干这件事儿,但没必要专门为展示个Demo去花钱 ...
- Android手机屏幕RTMP推流工具
Android手机屏幕RTMP推流工具是基于ffmpeg+opencv开发的C++(eclipse.androidstudio)程序,是一款可以将安卓手机屏幕上的任何内容推送到任意一款rtmp服务器上 ...
- android手机屏幕总是闪烁,手机屏幕闪烁是什么原因
手机屏幕闪烁会严重影响到我们对手机的使用,那么在遇到这种情况的时候我们应该怎么解决呢?下面是小编精心为你整理的手机屏幕闪烁的原因,一起来看看. 手机屏幕闪烁的原因 其实很多时候是由于静电造成的,我们可 ...
最新文章
- MAC终端密钥登录自动输入密码
- Java条形码生成技术-Barcode4j
- 《剑指offer》孩子们的游戏---约瑟夫问题
- 58或与赶集合并,几人欢喜几人愁
- 【我评】——关于Web标准
- #425[div2]
- 天天工作拧螺丝,怎么突破瓶颈?
- javascript_php 正则匹配 转
- icem划分网格步骤_ICEM CFD教程-icem网格划分教程
- [裴礼文数学分析中的典型问题与方法习题参考解答]4.3.1
- vmware linux top si高以及网卡队列、软负载相关优化
- Linux嵌入式开发入门(一)——初探嵌入式开发板的基本使用
- 使用python创建数组的方法
- gis 数据框裁剪_【计算摄影】计算机如何学会自动裁剪图片(自动构图)?
- 钢筋探测器行业研究及十四五规划分析报告
- 鬼故事~ 媚娘[完结版]
- BO4 SDK 检索所有使用了某个universe object的报表
- Scratch软件编程等级考试二级——201909
- Spark源码环境问题
- PID控制的理解与具体实现