我正在構建一個應用程序來播放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