gpt4 book ai didi

objective-c - MPMoviePlayerController 控件在 UIModalPresentationFormSheet 样式模式中打开并且用户使视频全屏时

转载 作者:行者123 更新时间:2023-11-28 19:22:16 25 4
gpt4 key购买 nike

在我的 iPad 应用程序中,我有一个 UIButton,它调用 IBAction 来调用 View Controller 作为模态来显示视频。我希望模态显示为 720x405,这部分看起来没问题。这是按钮正在执行的 IBAction 代码:

    -(IBAction)videoPlayerTest:(id)sender {
VideoModalViewController *vc = [[VideoModalViewController alloc] initWithNibName: @"VideoModalViewController" bundle: nil];
vc.fileName = @"testvideo.m4v";
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:vc animated: YES];
vc.view.superview.frame = CGRectMake(0, 0, 720, 405);
vc.view.superview.center = self.view.center;
[vc release];
}

模式出现在我想要的地方,控件在 MPMoviePlayerController 上响应;慢跑栏、暂停、播放等,但如果用户点击全屏按钮,视频确实可以全屏显示,但之后 MPMoviePlayerController 将不会响应播放器控件上的任何后续点击。如果我删除 modalPresentationStyle 行它会工作,但模式出现在全屏 View 而不是我想要的 720x405 模式。我已经添加了 Observers 来尝试调整框架大小并在用户使电影 Controller 全屏并返回窗口时重新居中,但它似乎根本没有帮助。这是代码。

    - (void)willEnterFullscreen:(NSNotification*)notification {
NSLog(@"willEnterFullscreen");
[self setModalPresentationStyle:UIModalPresentationFullScreen];
self.view.frame = CGRectMake(0, 0, 1024, 768);
self.view.center = self.view.center;
}

- (void)willExitFullscreen:(NSNotification*)notification {
NSLog(@"willExitFullscreen");
[self setModalPresentationStyle:UIModalPresentationFormSheet];
self.view.frame = CGRectMake(0, 0, 720, 405);
self.view.center = self.view.center;
}

- (void)playMovie {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];

NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0, 0, 720, 405);
moviePlayer.view.backgroundColor = [UIColor grayColor];
[moviePlayer prepareToPlay];
[moviePlayer play];
}

这是我的第一篇文章——希望我做对了,并提供了有关我遇到的问题的足够信息。

最佳答案

我已经解决了我的问题。我不知道 MPMoviePlayerViewController,我创建了它并将其用作我的模态。效果很好。

    -(void)playVideo:(NSString *)fileName {
NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentModalViewController:mpViewController animated:NO];
[[mpViewController moviePlayer] play];
}

-(IBAction)videoPlayerTest:(id)sender {
[self playVideo:@"testvideo.m4v"];
}

我想我会发布我的想法,以防其他人遇到同样的情况

关于objective-c - MPMoviePlayerController 控件在 UIModalPresentationFormSheet 样式模式中打开并且用户使视频全屏时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7740436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com