iOS端VR視頻播放

下面是我看了谷歌的一個(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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容