我正在构建一个应用程序来播放360视频 - 一切都很好!iOS Objective-C Xcode - 如何开始播放风景视频
但是,我希望视频仅在手机以横向为导向时才开始播放!如果在肖像中,它应该显示一条消息“请把你的手机放在风景中”,如果是的话 - 开始播放视频。 ..
任何人有什么想法如何实现这一目标?
这将是惊人的:)
谢谢!
编辑:
我Viewcontroller.m
//
// ViewController.m
// video360test
//
// Created by linyize on 16/6/20.
// Copyright © 2016年 islate. All rights reserved.
//
#import "ViewController.h"
#import "Video360ViewController.h"
#import "CardboardViewController.h"
#import "CardboardSDK.h"
@implementation ViewController
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (IBAction)playURL:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://7b1gcw.com1.z0.glb.clouddn.com/demo1.mp4"];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:@"HTY360PlayerVC" bundle:nil url:url];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil ];
}
}
- (IBAction)playFileffpvr:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo1" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:@"HTY360PlayerVC" bundle:nil url:url];
[videoController VRMode:true];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil];
}
}
- (IBAction)playFileff360:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo1" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:@"HTY360PlayerVC" bundle:nil url:url];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil];
}
}
- (IBAction)playFile2:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"boa" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:@"HTY360PlayerVC" bundle:nil url:url];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil];
}
}
- (IBAction)playFileffp:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"boa" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:@"HTY360PlayerVC" bundle:nil url:url];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil];
}
}
@end
@implementation LandscapeNavController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationBarHidden=YES;
}
-(BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
编辑2:
按钮正确显示现在警报:
- (IBAction)playFileffpvr:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo1" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait)
[self doSomething];
else
[self doSomethingElse];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:@"HTY360PlayerVC" bundle:nil url:url];
[videoController VRMode:true];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil];
}
}
和警报被显示:
-(void)doSomething
{
//Show Alert
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Simple" message:@"Turn your device to Landscape." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
NSLog(@"Cancel");
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
NSLog(@"OK");
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated: YES completion: nil];
}
-(void)doSomethingElse
{
//Function Body
//play the file
}
您是否在使用MPMoviePlayerController播放视频? –
谢谢回复, 不,我使用https://github.com/islate/SlateVideo360 但是,如果你有什么用MPMovie工作,我也许能使其与一个工作? – tibewww
如果您正在演示视频视图控制器,你可以强制它是唯一风景.... – Lefteris