参考:
这是我来到深圳工作的第一个星期,公司是做 VR 软件开发的。以前没怎么接触过,
我这边主要的工作是用 iOS 端开发VR视频播放的一个开发工作。
所以第一个星期需要自学这方面知识,下面是我看了谷歌的一个VR在iOS端开发的文档写的一个demo。
第一步是需要用cocoaPods导入谷歌开发的一个第三方:CardboardSDK,怎么导入就不多说了,
第二步,在导入第三方后在ViewController.m文件导入 #import “GCSVideoView.h”
遵循代理:GCSVideoViewDelegate
GCSVideoView GCSVideoView *_VRPlayerView = [[GCSVideoView alloc]initWithFrame:self.view.bounds];_VRPlayerView.delegate = self; 显示CardboardButton :
_VRPlayerView.enableCardboardButton = YES;
是否可以全屏 : _VRPlayerView.enableFullscreenButton = YES;
在GCSVideoView上加载VR视频 :
[_VRPlayerView loadFromUrl:[NSURL URLWithString:@"http://v1.mukewang.com/a45016f4-08d6-4277-abe6-bcfd5244c201/L.mp4"]];
1
1
实现代理方法
#pragma mark ----GCSVideoViewDelegate----
//GCSVideoView的点击事件
-(void)widgetViewDidTap:(GCSWidgetView *)widgetView{
if (_isPaused) {
[_VRPlayerView resume];
}else{
[_VRPlayerView pause];
}
_isPaused = !_isPaused;
}
//视频播放到某个位置时触发事件
-(void)videoView:(GCSVideoView *)videoView didUpdatePosition:(NSTimeInterval)position{
if (position == videoView.duration) {
[_VRPlayerView seekTo:0];
[_VRPlayerView resume];
}
}
//视频播放失败
-(void)widgetView:(GCSWidgetView *)widgetView didFailToLoadContent:(id)content withErrorMessage:(NSString *)
errorMessage
{
NSLog(@"播放错误");
}
第一步是需要用cocoaPods导入谷歌开发的一个第三方:CardboardSDK,怎么导入就不多说了,
第二步,在导入第三方后在ViewController.m文件导入 #import “GCSVideoView.h”
遵循代理:GCSVideoViewDelegate
GCSVideoView GCSVideoView *_VRPlayerView = [[GCSVideoView alloc]initWithFrame:self.view.bounds];_VRPlayerView.delegate = self; 显示CardboardButton :
_VRPlayerView.enableCardboardButton = YES;
是否可以全屏 :
_VRPlayerView.enableFullscreenButton = YES; 在GCSVideoView上加载VR视频 :
[_VRPlayerView loadFromUrl:[NSURL URLWithString:@"http://v1.mukewang.com/a45016f4-08d6-4277-abe6-bcfd5244c201/L.mp4"]];
• 1
• 1
实现代理方法
#pragma mark ----GCSVideoViewDelegate----
//GCSVideoView的点击事件
-(void)widgetViewDidTap:(GCSWidgetView *)widgetView{
if (_isPaused) {
[_VRPlayerView resume];
}else{
[_VRPlayerView pause];
}
_isPaused = !_isPaused;
}
//视频播放到某个位置时触发事件
-(void)videoView:(GCSVideoView *)videoView didUpdatePosition:(NSTimeInterval)position{
if (position == videoView.duration) {
[_VRPlayerView seekTo:0];
[_VRPlayerView resume];
}
}
//视频播放失败
-(void)widgetView:(GCSWidgetView *)widgetView didFailToLoadContent:(id)content withErrorMessage:(NSString *)
errorMessage
{
NSLog(@"播放错误");
}