功能:让本机的视频在其他设备上播放。
demo 学习中
关键词: cling
demo from: DROID DLNA
关于投屏的原理,协议相关的知识已经在上一篇中说明。
关于设备搜索,查找等不在此处说明。
投屏系统中分: 设备 服务 控制点。
当需要把A 设备中的视频 投屏到 B 设备。
重点是:如何生成本地视频的URL, 这样才能通过 控制点 设置play url 到 播放端。
跟踪demo 代码发现,播放的这个本地视频,返回的是一个xml 数据。节点中提供了这些视频的 thumb , url 。
ContentDirectoryService
这个类中的browse 方法,实现了数据查询和生成方法。
中间的代码写的非常复杂,在
MethodActionExecutor
中用了反射最终调用到这里。 其中的两个service(Local & remote 都不是真正的service)
本地文件的信息在初始化的时候就被全部扫描并添加进来:
ContentTree
addNode
并且生成了 每个节点的url;
这是demo 中生成的 video item 节点
SVID_20170929_115451<unknown>
object.item.videoItem
http://10.4.58.82:8192/storage/emulated/0/msi/.videothumb/video_thumb_video-item-27559.png
http://10.4.58.82:8192/video-item-27559
这是demo 中生成单个播放ship video Item 的方法:
DevicesActivity
String id = ContentTree.VIDEO_PREFIX
+ cursor.getInt(cursor
.getColumnIndex(MediaStore.Video.Media._ID));
String title = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
String creator = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST));
String filePath = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
String mimeType = cursor
.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
long size = cursor.getLong(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
long duration = cursor
.getLong(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
String resolution = cursor
.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.RESOLUTION));
String description = cursor
.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DESCRIPTION));
Res res = new Res(new MimeType(mimeType.substring(0,
mimeType.indexOf('/')), mimeType.substring(mimeType
.indexOf('/') + 1)), size, "http://"
+ mediaServer.getAddress() + "/" + id);
res.setDuration(duration / (1000 * 60 * 60) + ":"
+ (duration % (1000 * 60 * 60)) / (1000 * 60) + ":"
+ (duration % (1000 * 60)) / 1000);
res.setResolution(resolution);
VideoItem videoItem = new VideoItem(id, ContentTree.VIDEO_ID,
title, creator, res);
// add video thumb Property
String videoSavePath = ImageUtil.getSaveVideoFilePath(filePath,
id);
DIDLObject.Property albumArtURI = new DIDLObject.Property.UPNP.ALBUM_ART_URI(
URI.create("http://" + mediaServer.getAddress()
+ videoSavePath));
Property[] properties = { albumArtURI };
videoItem.addProperties(properties);
videoItem.setDescription(description);
videoContainer.addItem(videoItem);
videoContainer
.setChildCount(videoContainer.getChildCount() + 1);
ContentTree.addNode(id,
new ContentNode(id, videoItem, filePath));
HTTP 视频播放服务:
电视会通过之前手机生成的 视频节点信息中的Uri ,到手机端 请求视频。
处理部分: HttpServer,这个文件是自己实现的,而不是cling 提供的。
String itemId = uri.replaceFirst("/", "");
itemId = URLDecoder.decode(itemId);
String newUri = null;
if( ContentTree.hasNode(itemId) ) {
ContentNode node = ContentTree.getNode(itemId);
if (node.isItem()) {
newUri = node.getFullPath();
}
}
一些其他的关键词:
DMS:Digital Media Server 数字媒体服务器
DMP:Digital Meidal Player : 播放器
DMC : Controller 控制器
DMR: Renderer 渲染器