ios - 在 iOS 7 横向模式下播放视频

标签 ios video landscape

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

这是当前的视频代码。

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

在上面的代码中,我如何让它工作以便它在横向模式下播放。请指导我。卡在这个上面很久了。

最佳答案

使用电影播放器​​将其添加到您的 View Controller

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

关于ios - 在 iOS 7 横向模式下播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24156808/

相关文章:

ios - 为什么我所有的 View Controller 都是方形的?

ios - 如何使用GCM实现对iOS的可靠投递?

android - invalid_grant 尝试新的 Apple ID 登录时

Swift 相机应用程序 - 启用横向模式右/左

ios - 显示 UIBarButtonItem 菜单时获取事件

安卓相机2 : How to access every single frames while Recording video?

video - 如何在不实际生成视频切片的情况下使用 ffmpeg 提取视频切片的总时间?

audio - 将视频中的振荡运动转换为频率

android - SlidingPaneLayout setCoveredFadeColor () 和 setSliderFadeColor()

Android 以当前方向开始布局,之后禁用旋转