0

I am aware questions like this one may already be out there but for the sake of others like me I will go ahead and ask

I have a app that is set to only allow portrait orientation but this setting affects my videos as I would like only the videos to be able to play in landscape also. Is there a method I can add unto my .m file to make this work? Here is my code;

 #import "BIDVideosViewController.h"

 @interface BIDVideosViewController ()


 @end

 @implementation BIDVideosViewController

 @synthesize moviePlayer ;


 @synthesize tableList;


 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 {
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self) {
    // Custom initialization
 }
 return self;
 }


 - (void)viewDidLoad
 {
 [super viewDidLoad];
 UITableView *table = [[UITableView alloc]initWithFrame:self.view.bounds];
 [table setDelegate:self];
 [table setDataSource:self];
 [self.view addSubview:table];
 tableList = [[NSMutableArray alloc] initWithObjects:@"Gangan",@"SwimGood",@"German Ice", nil];

 }

 - (void)didReceiveMemoryWarning
 {
 [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }

 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
 return [tableList count];
 }

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
 static NSString *DisclosureButtonIdentifier = @"DisclosurebutotonIdentifier";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DisclosureButtonIdentifier];
 if (cell == nil)
 {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DisclosureButtonIdentifier];
 }

 NSInteger row = [indexPath row];
 NSString *rowString = [tableList objectAtIndex:row];
 cell.textLabel.text = rowString;

 return cell;
 }




 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
{
    NSBundle *str = [tableList objectAtIndex:indexPath.row];
    if ([str isEqual:@"Gangan"])
    {
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *thePath = [bundle pathForResource:@"Gangan" ofType:@"mp4"];
        NSURL *theurl = [NSURL fileURLWithPath:thePath];
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];

        [moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES];

        [moviePlayer play];
    }
    else if ([str isEqual:@"SwimGood"])
    {
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *thePath = [bundle pathForResource:@"SwimGood" ofType:@"mp4"];
        NSURL *theurl = [NSURL fileURLWithPath:thePath];
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
        [moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES];

        [moviePlayer play];

    }
    else if ([str isEqual:@"German Ice"])
    {
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *thePath = [bundle pathForResource:@"German Ice" ofType:@"mp4"];
        NSURL *theurl = [NSURL fileURLWithPath:thePath];
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
        [moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES];

        [moviePlayer play];
    }

   }
   }
   @end
DanKiiing
  • 102
  • 1
  • 11
  • possible duplicate of [MPMoviePlayerController should only in landscape mode](http://stackoverflow.com/questions/13011266/mpmovieplayercontroller-should-only-in-landscape-mode) – Brian Diggs Oct 25 '12 at 22:06

1 Answers1

1

In your view controller .m file, you should have

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

There you can return YES for supported orientations, which will enable you to rotate video.

Also not that if you use UINavigationController, this aproach wont work, unless all views managed by UINavigationController implement - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation the same way.

Also in your Targets -> "You Project" -> Summary, you can set supported orientations.

Edit: go here an look for UIInterfaceOrientation. There you have constants you need.

I would write it like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationPortrait)
       return YES;  
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
       return YES; 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
       return YES;
}
Martin Berger
  • 1,639
  • 3
  • 18
  • 39
  • thanks..say i wanted to use 'lanscapeleft' and 'landscaperight' how do i write that, could you please amend the answer :) thanks @MartinBerger – DanKiiing Oct 25 '12 at 09:53