下面是我看了谷歌的一個(gè)VR在iOS端開(kāi)發(fā)的文檔寫(xiě)的一個(gè)demo。
第一步是需要用cocoaPods導(dǎo)入谷歌開(kāi)發(fā)的一個(gè)第三方:CardboardSDK,怎么導(dǎo)入就不多說(shuō)了,這里需要注意的一點(diǎn)是谷歌方面的第三方導(dǎo)入需要翻墻,一般的翻墻軟件是不可行的,需要用到VPN進(jìn)行翻墻。
第二步,在導(dǎo)入第三方后在ViewController.m文件導(dǎo)入 #import “GCSVideoView.h”
遵循代理:GCSVideoViewDelegate
初始化:
GCSVideoView *_VRPlayerView = [[GCSVideoView alloc]initWithFrame:self.view.bounds];
確認(rèn)代理:_VRPlayerView.delegate = self;
顯示CardboardButton :
_VRPlayerView.enableCardboardButton = YES;
是否可以全屏 :
_VRPlayerView.enableFullscreenButton = YES;
在GCSVideoView上加載VR視頻 :
[_VRPlayerView loadFromUrl:[NSURLURLWithString:@"http://v1.mukewang.com/a45016f4-08d6-4277-abe6-bcfd5244c201/L.mp4"]];
實(shí)現(xiàn)代理方法
#pragma mark ----GCSVideoViewDelegate----//GCSVideoView的點(diǎn)擊事件-(void)widgetViewDidTap:(GCSWidgetView *)widgetView{
if(_isPaused) {? ? ?
? [_VRPlayerView resume];?
? }else{? ? ?
? [_VRPlayerView pause];?
? }
? ? _isPaused = !_isPaused;}
//視頻播放到某個(gè)位置時(shí)觸發(fā)事件
-(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(@"播放錯(cuò)誤");
}
應(yīng)大家的要求,我寫(xiě)了個(gè)DEMO上傳到了github,有需要的可以去下載來(lái)看看。希望大家能給個(gè)星哦,順便給這篇文章點(diǎn)個(gè)贊吧。以后會(huì)更新更多的技術(shù)貼,謝謝大家支持。 ??VRDemo