Google Cast Function
依赖
com.android.support:mediarouter-v7
com.google.android:gms:play-services-cast-framework
Cast 过程
1)framework提供一个CastContext singleton给APP使用
2)MediaRoute 提供设备扫描
3)CastSession (由CastContext.getSessionManager().getCurrentCastSession()提供) 通过用户选取MediaRouter扫描dialog建立device connect
4)RemoteMediaClient ( 由castsession 得到mCastSession.getRemoteMediaClient()) 控制Receiver device 的音视频play,pause,etc
5)MediaMetadata代表需要cast mediaitem
privateMediaInfo buildMediaInfo() {
MediaMetadata movieMetadata = newMediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
movieMetadata.putString(MediaMetadata.KEY_SUBTITLE,mSelectedMedia.getStudio());
movieMetadata.putString(MediaMetadata.KEY_TITLE, mSelectedMedia.getTitle());
movieMetadata.addImage(new WebImage(Uri.parse(mSelectedMedia.getImage(0))));
movieMetadata.addImage(new WebImage(Uri.parse(mSelectedMedia.getImage(1))));
return new MediaInfo.Builder(mSelectedMedia.getUrl())
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setContentType("videos/mp4")
.setMetadata(movieMetadata)
.setStreamDuration(mSelectedMedia.getDuration() * 1000)
.build();
}
6)RemoteMediaClient 控制Receiver device load
remoteMediaClient.load(buildMediaInfo(),autoPlay, position);
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。