在横向模式iOS 7中播放视频

时间:2014-06-11 07:13:55

标签: ios video landscape

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

这是当前的视频代码。

    _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];

在上面的代码中,如何使其工作以便以横向模式播放。请指导我这个。长期坚持这一点。

2 个答案:

答案 0 :(得分:0)

使用电影播放器​​

将其添加到您的viewcontroller
@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;
}

答案 1 :(得分:0)

您可能应该在viewController中实现shouldAutorotateToInterfaceOrientationsupportedInterfaceOrientations方法

@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;
}