Obj C - Google Cardboard 暂停视频不工作
Obj C - Google Cardboard pause video not working
我已将 Google Cardboard/VRView SDK 实施到我的项目中,并正在尝试加载视频,以便在应用程序首次加载时暂停。
然而,尽管将 _isPaused
变量设置为 YES
/TRUE
它似乎不起作用,视频会在加载视图控制器时自动播放。
有人用过这个吗?
#import <UIKit/UIKit.h>
#import "NewViewController.h"
#import "GCSVideoView.h"
@interface NewViewController ()
@property (nonatomic) IBOutlet GCSVideoView *viewView;
@end
@implementation NewViewController {
BOOL _isPaused;
}
- (instancetype)init {
self = [super initWithNibName:nil bundle:nil];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
_viewView.enableFullscreenButton = YES;
_viewView.enableCardboardButton = NO;
_isPaused = YES;
// Load the sample 360 video, which is of type stereo-over-under.
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
[_viewView loadFromUrl:[[NSURL alloc] initFileURLWithPath:videoPath]];
}
#pragma mark - GVRVideoViewDelegate
- (void)widgetViewDidTap:(GCSWidgetView *)widgetView {
if (_isPaused) {
[_viewView resume];
} else {
[_viewView pause];
}
_isPaused = !_isPaused;
}
- (void)widgetView:(GCSWidgetView *)widgetView didLoadContent:(id)content {
NSLog(@"Finished loading video");
}
- (void)widgetView:(GCSWidgetView *)widgetView
didFailToLoadContent:(id)content
withErrorMessage:(NSString *)errorMessage {
NSLog(@"Failed to load video: %@", errorMessage);
}
- (void)videoView:(GCSVideoView*)videoView didUpdatePosition:(NSTimeInterval)position {
// Loop the video when it reaches the end.
if (position == videoView.duration) {
[videoView seekTo:0];
[videoView resume];
}
}
@end
- (void)widgetView:(GVRWidgetView *)widgetView didLoadContent:(id)content {
NSLog(@"Finished loading video");
[self.videoView pause];
self.isPaused = YES;
}
尝试将其添加到您的 didLoadContent 委托方法中。这将确保视频在加载后暂停。
我已将 Google Cardboard/VRView SDK 实施到我的项目中,并正在尝试加载视频,以便在应用程序首次加载时暂停。
然而,尽管将 _isPaused
变量设置为 YES
/TRUE
它似乎不起作用,视频会在加载视图控制器时自动播放。
有人用过这个吗?
#import <UIKit/UIKit.h>
#import "NewViewController.h"
#import "GCSVideoView.h"
@interface NewViewController ()
@property (nonatomic) IBOutlet GCSVideoView *viewView;
@end
@implementation NewViewController {
BOOL _isPaused;
}
- (instancetype)init {
self = [super initWithNibName:nil bundle:nil];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
_viewView.enableFullscreenButton = YES;
_viewView.enableCardboardButton = NO;
_isPaused = YES;
// Load the sample 360 video, which is of type stereo-over-under.
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
[_viewView loadFromUrl:[[NSURL alloc] initFileURLWithPath:videoPath]];
}
#pragma mark - GVRVideoViewDelegate
- (void)widgetViewDidTap:(GCSWidgetView *)widgetView {
if (_isPaused) {
[_viewView resume];
} else {
[_viewView pause];
}
_isPaused = !_isPaused;
}
- (void)widgetView:(GCSWidgetView *)widgetView didLoadContent:(id)content {
NSLog(@"Finished loading video");
}
- (void)widgetView:(GCSWidgetView *)widgetView
didFailToLoadContent:(id)content
withErrorMessage:(NSString *)errorMessage {
NSLog(@"Failed to load video: %@", errorMessage);
}
- (void)videoView:(GCSVideoView*)videoView didUpdatePosition:(NSTimeInterval)position {
// Loop the video when it reaches the end.
if (position == videoView.duration) {
[videoView seekTo:0];
[videoView resume];
}
}
@end
- (void)widgetView:(GVRWidgetView *)widgetView didLoadContent:(id)content {
NSLog(@"Finished loading video");
[self.videoView pause];
self.isPaused = YES;
}
尝试将其添加到您的 didLoadContent 委托方法中。这将确保视频在加载后暂停。