【问题标题】:Video List in Portrait; Video playback in Landscape纵向视频列表;横向视频播放
【发布时间】:2012-06-15 16:01:31
【问题描述】:

我有一个用户可以选择观看的视频列表。所有视频都包含在应用资源中并在本地播放。

除了一件事,我的一切都很好。我不知道如何强制视频播放为横向模式。

我正在使用此代码在选择视频时显示视频播放器:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    VideoPlayerViewController *detailViewController = [[VideoPlayerViewController alloc] init];
    detailViewController.delegate = self;

    detailViewController.contentPath = [[videos objectAtIndex:indexPath.row] objectAtIndex:1];

    [self presentModalViewController:detailViewController animated:YES];
}

我的播放器类 VideoPlayerViewController 使用上面代码中设置的 contentPath 加载播放器并播放视频。

我可以旋转手机,它会切换到横向,但如果我将手机旋转回纵向,视频也会旋转。我的播放器有以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

任何想法为什么它允许旋转回纵向以及如何开始横向播放?

我正在寻找与原生 YouTube 应用类似的功能。

谢谢

【问题讨论】:

    标签: iphone ios5 mpmovieplayercontroller


    【解决方案1】:

    在 VideoPlayerViewController viewDidLoad 方法和 shouldautorotate 方法中使用这个:

     [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
    
     [[self view] setBounds:CGRectMake(0, 0, 480, 320)];
     [[self view] setCenter:CGPointMake(160, 240)];
     [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
    

    【讨论】:

    • 这真是太棒了 Safecase。它完美地工作。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多