使用 GVRSDK 加载VR图片/视频

/ 1评 / 0

项目中使用到了GVRSDK去展示VR的图片和视频,使用起来还是很简单的,我直接使用的pod导入SDK库

pod 'GVRSDK'

首先来看加载图片,还是比较简单的,只需要做好配置,然后将图片资源加载即可:

- (void)createControl{
    GVRPanoramaView *imageView = [[GVRPanoramaView alloc] init];
    imageView.enableFullscreenButton = YES;
    imageView.enableCardboardButton = YES;
    imageView.enableTouchTracking = YES;
    imageView.enableInfoButton=NO;
    imageView.frame = CGRectMake(0,0,kDEVICE_WIDTH,kDEVICE_HEIGHT - 64);
    [self.view addSubview:imageView];
    [imageView loadImage:self.photoImage ofType:kGVRPanoramaImageTypeMono];
}

加载视频可能会涉及到几个代理方法,不过几乎与加载图片相同:

- (void)createControl{
    _videoView = [[GVRVideoView alloc] init];
    _videoView.delegate = self;
    _videoView.enableFullscreenButton = YES;
    _videoView.enableCardboardButton = YES;
    _videoView.enableTouchTracking = YES;
    _videoView.enableInfoButton=NO;
    _videoView.frame = CGRectMake(0,0,kDEVICE_WIDTH,kDEVICE_HEIGHT-64);
    //_isPaused = YES;
    //_videoView.volume = 0.0f;
    [self.view addSubview:_videoView];
    
    [_videoView loadFromUrl:self.videoUrl];
    
    
    _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(10, 10, kDEVICE_WIDTH - 20, 2)];
    _progressView.layer.cornerRadius = 1;
    [_videoView addSubview:_progressView];
}

#pragma mark - GVRVideoViewDelegate
- (void)widgetViewDidTap:(GVRWidgetView *)widgetView {
    if (_isPaused) {
        [_videoView play];
    } else {
        [_videoView pause];
    }
    _isPaused = !_isPaused;
}

- (void)widgetView:(GVRWidgetView *)widgetView didLoadContent:(id)content {
    SRQLog(@"Finished loading video");
    [_videoView play];
    _isPaused = NO;
}

- (void)widgetView:(GVRWidgetView *)widgetView
didFailToLoadContent:(id)content
  withErrorMessage:(NSString *)errorMessage {
    SRQLog(@"Failed to load video: %@", errorMessage);
}

- (void)videoView:(GVRVideoView*)videoView didUpdatePosition:(NSTimeInterval)position {
    // Loop the video when it reaches the end.
    if (position == videoView.playableDuration || isnan(position)) {
        [_progressView setProgress:0];
        [_videoView seekTo:0];
        [_videoView play];
    }else{
        [_progressView setProgress:(position/videoView.playableDuration) animated:YES];
    }
}

一条回应:“使用 GVRSDK 加载VR图片/视频”

  1. xxxxx说道:

    GVRPanoramaView 加载图片 为什么 总是提示 不在主线程