仅自动旋转 MpMoviePlayerControler iOS 6 [英] AutoRotate ONLY MpMoviePlayerControler iOS 6

查看:21
本文介绍了仅自动旋转 MpMoviePlayerControler iOS 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧伙计们和其他人一样的问题.如果我编辑 .plist 以支持所有方向,我就能让它工作,但我只需要在我的 MPMoviePlayerController 上支持旋转(也许在我的 MWPhotoBrwoser 图像上)

okay guys Same question as everyone else. I got it to work if i edited the .plist to support all orientation, but i only need to support rotation at my MPMoviePlayerController (and maybe at my MWPhotoBrwoser images)

我的代码:视图控制器.h

My code: Viewcontroller.h

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

@interface MusikViewController : UIViewController{
    AVAudioPlayer *audioPlayer;

}

//tilføjer vores film afspiller
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;


//Laver de to knapper
//Musik knap
- (IBAction)Play:(UIButton *)sender;
//Film knap
- (IBAction)playButton:(id)sender;

//info knap
- (IBAction)info:(id)sender;


@end

Viewcontroller.m

Viewcontroller.m

#import "MusikViewController.h"



@implementation MusikViewController
@synthesize moviePlayer;


- (IBAction)Play:(UIButton *)sender
{
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/roteWeste.mp4", [[NSBundle mainBundle] resourcePath]]];

    NSError *error;
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    audioPlayer.numberOfLoops = -1;

    if (audioPlayer == nil){
        NSLog(@"Der skete en fejl, prøv at genstarte app'en, hvis problemet bliver ved, prøv da at send en mail til Mrostgaard@gmail.com");
    }
    else
        [audioPlayer play];
}

- (IBAction)playButton:(id)sender {

    NSString *videoFile = [[NSBundle mainBundle] pathForResource:@"RoteVeste2" ofType:@"m4v"];

    moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:videoFile]];

    [self.view addSubview:moviePlayer.view];

    moviePlayer.fullscreen = YES;

    moviePlayer.allowsAirPlay = YES;
    moviePlayer.controlStyle = MPMovieControlModeVolumeOnly;


    [moviePlayer play];


}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
            return YES;
        }
        else return NO;
    }
    else
    {
        if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
            return YES;
        }
        else return NO; }
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [audioPlayer stop]; // Or pause
}


- (IBAction)info:(id)sender {
}
@end

我似乎无法让它工作.代码:

i just can't seem to make it work. The code:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
            return YES;
        }
        else return NO;
    }
    else
    {
        if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
            return YES;
        }
        else return NO; }
}

这只是我最近的尝试,但我几乎尝试了所有方法只需要旋转 MPMovieViewController.

Is just my latest try but i have tried almost everything Only need to rotate the MPMovieViewController.

我什至试过这个,无法让它工作http://fostah.com/ios/2012/09/27/ios6-orientation-handling.html

I have even tried this, could not get it to work http://fostah.com/ios/2012/09/27/ios6-orientation-handling.html

真的希望得到一些帮助!:)

Really hoping for some help! :)

推荐答案

阅读您的问题时:如果我编辑 .plist 以支持所有方向,我就可以工作,但我只需要在我的 MPMoviePlayerController 上支持旋转(也许在我的 MWPhotoBrwoser 图像中)",第一句话是你应该允许 .plist 中的所有方向.plist 中允许的方向应该是应用程序中不同视图控制器必须支持的所有方向的联合.

When reading your question: " I got it to work if i edited the .plist to support all orientation, but i only need to support rotation at my MPMoviePlayerController (and maybe at my MWPhotoBrwoser images)", the first remark would be that you should allow all orientations in the .plist. The allowed orientations in your plist should be the union of all orientations the different view controllers in your application must support.

无论你在特定的视图控制器中做什么,你将永远无法允许旋转到你的 plist 中不允许的方向.

Whatever you do in a specific view controller, you will never be able to allow rotation to an orientation that is not allowed in your plist.

然后由所有单独的视图控制器来说明特定视图控制器允许的方向.所以分步骤:

It is then up to all individual view controllers to say what orientations that particular view controller allows. So in steps:

  1. 允许 plist 中支持 at 的所有方向至少一个视图控制器
  2. 对于所有单独的视图控制器,使用 shouldAutorotateToInterfaceOrientation (iOS5) 和shouldAutorotate/supportedInterfaceOrientations (iOS6)
  1. Allow all orientations in the plist that are supported by at least one view controller
  2. For all individual view controllers, use the shouldAutorotateToInterfaceOrientation (iOS5) and shouldAutorotate / supportedInterfaceOrientations (iOS6)

这篇关于仅自动旋转 MpMoviePlayerControler iOS 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆