2014-06-11 79 views
2

在我的应用程序中,我试图使用来自服务器的URL播放视频。我使用UITableView来显示视频列表,并通过点击列表中的单元格,视频将在子视图中播放。现在我想以横向模式播放视频。在横向模式下播放视频iOS 7

这是当前的视频代码。

_movieplayer = [[MPMoviePlayerController alloc]initWithContentURL: [NSURL URLWithString:[self urlencode:self.strPlayUrl]]]; 
    [[_movieplayer view] setFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; 
    [self.view addSubview: [_movieplayer view]]; 
    [_movieplayer setShouldAutoplay:YES]; 
    [_movieplayer prepareToPlay]; 

    [self.movieplayer play]; 

在上面的代码中,我如何使它工作以便在横向模式下播放。请在此引导我。长期以来一直陷在这个问题上。

+0

好的问题shouldAutorotateToInterfaceOrientationsupportedInterfaceOrientations方法。也有同样的问题。你有没有得到解决方案? – Mohit

回答

0

这对您的ViewController添加与movieplayer

@property (nonatomic, strong) MPMoviePlayerController* mpc; 

- (void)setUpMPC 
{ 
    NSURL* m = [[NSBundle mainBundle] URLForResource:@"YourVideo" withExtension:@"mp4"]; 
    MPMoviePlayerController* mp = [[MPMoviePlayerController alloc] initWithContentURL:m]; 
    self.mpc = mp; // retain policy 
    self.mpc.shouldAutoplay = NO; 
    [self.mpc prepareToPlay]; 
    self.mpc.view.frame = CGRectMake(50, 50, self.view.bounds.size.width, self.view.bounds.size.height); 
} 

-(NSUInteger)supportedInterfaceOrientations { 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 
     return UIInterfaceOrientationMaskAll; 
    } 
    return UIInterfaceOrientationMaskLandscape; 
} 
+0

我已将此代码添加到其不起作用 – Shanthanu

+0

您的应用是否允许横向摆放? – vnchopra

+0

在一般 - >部署信息 - >打勾横向方向 – vnchopra

0

也许你应该实现在您的viewController

@property (nonatomic, strong) MPMoviePlayerController* moviePlayerController; 

#pragma mark # - Init - 

- (void) createAndPlayMovieForURL: (NSURL*) movieURL 
{ 
    self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL: movieURL]; 
    [self.moviePlayerController.view setFrame: self.view.bounds]; 

    [self.view addSubview: self.moviePlayerController.view]; 
    [self.view bringSubviewToFront: self.overlayView]; 
} 

#pragma mark - Rotation - 

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

- (NSUInteger) supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 
+0

我已经使用你的代码,它不工作 – Shanthanu

+0

你检查了'shouldAutorotateToInterfaceOrientation'和'supportedInterfaceOrientations'曾经呼吁过? – user3687611

+0

告诉我如何调用 – Shanthanu

相关问题