VR Virtual Reality 虚拟现实
CardBoard
世界上最流行和最易用的手机 VR 平台
DayDream
一个新的手机 VR 平台,低时延、更逼真、易交互。
VR SDK 同时支持 DayDream 和 CardBoard。
包含了一些用于创建 App 的简单 API 和支持 DayDream 手机、DayDream 控制器的复杂 API。
Google VR SDK 涵盖了 Android、IOS、Unity 三大平台
开发者可以下载上述连接中的代码,并运行其中的示例程序。
这些示例程序使用 VR SDK 中的几大特性:
VR View 允许开发者在网站或 app 中嵌入 360 度全景多媒体文件(图片和视频)。这个技术主要是提供给传统的开发者,可以通过在 app 中添加动态内容来提升用户体验。比如旅行或房地产类型的 app,可以让用户足不出户就体验到虚拟场景。
VR View 同时支持 web 和 Native app。
WebModern versions of Chrome on Windows, OSX, Linux, Android, and iOS.
Modern versions of Safari on OSX and iOS. Modern versions of Firefox
on Windows, OSX, and Linux. Modern versions of IE 11 and Edge on
Windows. NativeiOS 8 and higher. Android 4.4 (Kit Kat) and higher.
VR View 同时支持单声道和立体声的图片和视频,但是图片和视频的存储格式必须为 equirectangular-panoramic 格式,这是一种常见的摄像头尺寸支持的格式。
图片规格:
视频规格:
VR view 是客户端的显示技术,那么我们怎么去拍摄符合 VR view 要求的内容呢?
一个非常流行的,相对廉价的用来拍摄单声道相片和视频的设备。
Unity 插件
虚幻引擎
一个开源库
这个有点扯了,让开发者贡献 360 拍摄方法的白纸。。。
下面用伪代码展示如何用 VrPanoramaView 和 VrVideoView 展示 360 度图片和视频。
布局代码
- <com.google.vr.sdk.widgets.pano.VrPanoramaView android:id="@+id/pano_view"
- android:layout_margin="5dip" android:layout_width="match_parent" android:scrollbars="@null"
- android:layout_height="250dip" />
- <com.google.vr.sdk.widgets.video.VrVideoView android:id="@+id/video_view"
- android:layout_width="match_parent" android:scrollbars="@null" android:layout_height="250dip"
- />
Java 代码
- //展示全景图片
- panoWidgetView = (VrPanoramaView) findViewById(R.id.pano_view);
- //图片加载结果回调
- private class ActivityEventListener extends VrPanoramaEventListener {
- /**
- * Called by pano widget on the UI thread when it's done loading the image.
- */
- @Override public void onLoadSuccess() {
- loadImageSuccessful = true;
- }
- /**
- * Called by pano widget on the UI thread on any asynchronous error.
- */
- @Override public void onLoadError(String errorMessage) {
- loadImageSuccessful = false;
- Toast.makeText(SimpleVrPanoramaActivity.this, "Error loading pano: " + errorMessage, Toast.LENGTH_LONG).show();
- Log.e(TAG, "Error loading pano: " + errorMessage);
- }
- }
- //设置图片加载监听
- panoWidgetView.setEventListener(new ActivityEventListener());
- //加载图像的Bitmap数据 istr是一个文件输入流
- //VrPanoramaView.Options是用来配置图片格式的
- // TYPE_MONO 包含单一圆柱的全景图像
- // TYPE_STEREO_OVER_UNDER 图像包含了两个大小相等、垂直相交的圆柱全景图像。上图展示给左眼,下图展示给右眼。
- panoWidgetView.loadImageFromBitmap(BitmapFactory.decodeStream(istr), panoOptions);
- //展示全景视频
- videoWidgetView = (VrVideoView) findViewById(R.id.video_view);
- videoWidgetView.setEventListener(new ActivityEventListener());
- //VrVideoEventListener同时对视频加载和操作的回调
- private class ActivityEventListener extends VrVideoEventListener {
- /**
- * Called by video widget on the UI thread when it's done loading the video.
- */
- @Override public void onLoadSuccess() {
- Log.i(TAG, "Sucessfully loaded video " + videoWidgetView.getDuration());
- loadVideoStatus = LOAD_VIDEO_STATUS_SUCCESS;
- seekBar.setMax((int) videoWidgetView.getDuration());
- updateStatusText();
- }
- /**
- * Called by video widget on the UI thread on any asynchronous error.
- */
- @Override public void onLoadError(String errorMessage) {
- // An error here is normally due to being unable to decode the video format.
- loadVideoStatus = LOAD_VIDEO_STATUS_ERROR;
- Toast.makeText(SimpleVrVideoActivity.this, "Error loading video: " + errorMessage, Toast.LENGTH_LONG).show();
- Log.e(TAG, "Error loading video: " + errorMessage);
- }@Override public void onClick() {
- togglePause();
- }
- /**
- * Update the UI every frame.
- */
- @Override public void onNewFrame() {
- updateStatusText();
- seekBar.setProgress((int) videoWidgetView.getCurrentPosition());
- }
- /**
- * Make the video play in a loop. This method could also be used to move to the next video in
- * a playlist.
- */
- @Override public void onCompletion() {
- videoWidgetView.seekTo(0);
- }
- }
- //支持两种加载方式,从asset文件夹中或从一个uri中读取视频数据
- //VrVideoView.Options同样是用来配置视频格式的
- videoWidgetView.loadVideoFromAsset("congo.mp4", options);或videoWidgetView.loadVideo(fileInformation[0].first, fileInformation[0].second)除此外还有一些控制渲染、播放的方法:videoWidgetView.pauseRendering();
- videoWidgetView.resumeRendering();
- videoWidgetView.shutdown();
- videoWidgetView.playVideo();
- videoWidgetView.pauseVideo();
- shutdown()一定要在onDestroy()时调用,用来释放占用内存。
Google VR SDK 一个重要的特性就是一个为手机 VR 高度优化的一流的音频渲染引擎,给听众更真实的空间声音体验。
来源: http://lib.csdn.net/article/vr/42224