您的位置:首页 > 移动开发 > Android开发

vlc-android源码阅读笔记之视频播放器界面

2015-04-04 17:25 656 查看
vlc-android: 如何系统高于等于Android4.2就使用MediaRouter,然后在播放视频的最外层使用presentation来显示控制层(各种按钮,seekbar,textview之类的)
if (LibVlcUtil.isJellyBeanMR1OrLater()) {
// Get the media router service (miracast)
mMediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
mMediaRouterCallback = new MediaRouter.SimpleCallback() {
@Override
public void onRoutePresentationDisplayChanged(
MediaRouter router, MediaRouter.RouteInfo info) {
Log.d(TAG, "onRoutePresentationDisplayChanged: info="
+ info);
removePresentation();
}
};
}

createPresentation();
mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback);

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void createPresentation() {
if (mMediaRouter == null)
return;

// Get the current route and its presentation display.
MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(
MediaRouter.ROUTE_TYPE_LIVE_VIDEO);

Display presentationDisplay = route != null ? route.getPresentationDisplay() : null;

if (presentationDisplay != null) {
// Show a new presentation if possible.
Log.i(TAG, "Showing presentation on display: " + presentationDisplay);
mPresentation = new SecondaryDisplay(this, presentationDisplay);
mPresentation.setOnDismissListener(mOnDismissListener);
try {
mPresentation.show();
} catch (WindowManager.InvalidDisplayException ex) {
Log.w(TAG, "Couldn't show presentation!  Display was removed in "
+ "the meantime.", ex);
mPresentation = null;
}
}
}

如果低于Android4.2,没办法使用presentation来显示控制层,就只有在设置内容布局的时候把最外层的控制层布局放入到播放视频布局的外层
在程序里面使用showOerlay hideOverlay来控制覆盖层的显示与隐藏

布局只有显示播放视频的布局,显示控制层的任务就落在了presentation上面了,他可以在其他的显示器上面显示,这就是多屏显示
布局FrameLayout最里层是显示播放视频的布局,外层是控制层布局
setContentView(mPresentation == null ? R.layout.player : R.layout.player_remote_control);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: