2

如何动态调整 MPMoviePlayerController 的大小以修复 iPhone/iPad 的所有屏幕尺寸(纵向和横向)?

这是我的代码:

 - (void)viewDidLoad
{
[super viewDidLoad];

UIBarButtonItem *about = [[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleDone target:self action:@selector(openPopup)];
self.navigationItem.leftBarButtonItem = about;


NSURL *streamURL = [NSURL URLWithString:@"http:/streamUrl/playlist.m3u8"];

_streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];


self.streamPlayer.controlStyle = MPMovieControlStyleEmbedded;

[self.view addSubview: self.streamPlayer.view];

[self.streamPlayer play];


}

我也尝试添加

[self.streamPlayer.view setFrame:self.view.bounds];

但这使得视频不固定在屏幕上,如屏幕截图所示

在此处输入图像描述

我怎样才能让它修复所有不同设备的所有屏幕?提前致谢。

4

3 回答 3

2

我找到的最佳解决方案是使用以下

 CGFloat width = [UIScreen mainScreen].bounds.size.width;
 CGFloat height = [UIScreen mainScreen].bounds.size.height;

 [self.streamPlayer.view setFrame:CGRectMake(10, 10 ,height-20, width-70)];
于 2012-12-09T11:14:30.350 回答
0

我在 ios 5 中解决了这个问题:

AvPlayerLayer *avPlayerLayer =[[AVPlayerLayer alloc]init];
avPlayerLayer = [[AVPlayerLayer playerLayerWithPlayer:avPlayer] retain];
avPlayerLayer.frame = self.playerView.layer.bounds;
avPlayerLayer.transform = CATransform3DMakeRotation(M_PI / 2.0, 0, 0, 1);

[self.playerView.layer addSublayer:avPlayerLayer]; 

这里是 avPlayerLayer.transform 你可以在任何方向设置它。

于 2012-12-04T12:22:31.053 回答
0
 MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:contentURL]];
        if (moviePlayerViewController) {


            [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
            [moviePlayerViewController.moviePlayer setMovieSourceType:MPMovieSourceTypeFile];

            if ([moviePlayerViewController.moviePlayer respondsToSelector:@selector(setAllowsAirPlay:)]) {
                [moviePlayerViewController.moviePlayer setAllowsAirPlay:YES];
            }

            [[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerViewController queue:nil usingBlock:^(NSNotification *notification) {
                [[NSNotificationCenter defaultCenter] removeObserver:self];
                [self dismissMoviePlayerViewControllerAnimated];
            }];
            [moviePlayerViewController.moviePlayer play];
        }
于 2012-12-04T14:26:45.873 回答