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);