以前公司项目里要求实现VR视频播放,一直没有上传直到现在.
使用cocapods或者直接把CardboardSDK 拖拽到项目里
VR视频实现
在工程中导入#import "GCSVideoView.h"
代码实现
@interface ShowVRPlayViewController ()@property(nonatomic,strong)GCSVideoView *VRPlayerView;
@property(nonatomic,assign,getter=isPaused)BOOL paused;
@end
@implementation ShowVRPlayViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor whiteColor];
self.paused=NO;
[self.view addSubview:self.VRPlayerView];
[self photoVRLook]; //图片VR查看
}
#pragma mark === VR视频播放
-(GCSVideoView *)VRPlayerView
{
if (!_VRPlayerView) {
_VRPlayerView=[[GCSVideoView alloc]init];
_VRPlayerView.frame=CGRectMake(0, 100, self.view.frame.size.width, 300);
_VRPlayerView.delegate=self;
[_VRPlayerView loadFromUrl:[NSURL URLWithString:@"http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4"]];
_VRPlayerView.enableCardboardButton = YES;//VR设配
_VRPlayerView.enableFullscreenButton = YES;//全屏播放
}
return _VRPlayerView;
}
#pragma mark ----GCSVideoViewDelegate----
#pragma mark === GCSVideoView的点击事件
-(void)widgetViewDidTap:(GCSWidgetView *)widgetView{
if (self.isPaused) {
[self.VRPlayerView resume];
}else{
[self.VRPlayerView pause];
}
self.paused = !self.paused;
}
#pragma mark ==== 视频播放到某个位置时触发事件
-(void)videoView:(GCSVideoView *)videoView didUpdatePosition:(NSTimeInterval)position{
if (position == videoView.duration) {
[self.VRPlayerView seekTo:0];
[self.VRPlayerView resume];
}
}
#pragma mark ==== 视频播放失败
-(void)widgetView:(GCSWidgetView *)widgetView didFailToLoadContent:(id)content withErrorMessage:(NSString *)errorMessage{
NSLog(@"播放错误");
}
图片VR实现
项目导入#import "GCSPanoramaView.h"
代码实现
#import "GCSPanoramaView.h"@interface ShowVRPhotoViewController ()@property(nonatomic,strong)GCSPanoramaView *VRPhotoPlayerView;
@end
@implementation ShowVRPhotoViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor whiteColor];
[self.view addSubview:self.VRPhotoPlayerView];
}
#pragma mark === VR图片查看
-(GCSPanoramaView *)VRPhotoPlayerView
{
if (!_VRPhotoPlayerView) {
_VRPhotoPlayerView=[[GCSPanoramaView alloc]init];
_VRPhotoPlayerView.delegate=self;
_VRPhotoPlayerView.frame=CGRectMake(0, 100, self.view.frame.size.width, 300);
_VRPhotoPlayerView.enableCardboardButton = YES; _VRPhotoPlayerView.enableFullscreenButton = YES;
[_VRPhotoPlayerView loadImage:[UIImage imageNamed:@"andes.jpg"] ofType:kGCSPanoramaImageTypeStereoOverUnder];
}
return _VRPhotoPlayerView;
}
出现下列错误
解决方法
在工程中 找到build setting, 在搜索栏输入牵头对应的内容 如: ENABLE_BITCODE 如下图所示
把ENABLE_BITCODE 栏的YES 改为 no , 重新运行工程,至此问题完美解决.