gpt4 book ai didi

ios - "Done"MPMoviePlayerController 中的按钮在全屏模式下不起作用

转载 作者:行者123 更新时间:2023-11-28 20:33:55 25 4
gpt4 key购买 nike

好吧,我可以找到很多关于相同或相似问题和答案的问题......但是,没有什么可以帮助我。只有当我不使用属性“controlStyle”作为“MPMovieControlStyleFullscreen”时,“完成”按钮才有效。我试过这种方式..

    MPMoviePlayerController *mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
mpMoviePlayerController.controlStyle = MPMovieControlStyleNone;
[mpMoviePlayerController setUseApplicationAudioSession:NO];
[mpMoviePlayerController setScalingMode:MPMovieScalingModeAspectFit];
[mpMoviePlayerController setFullscreen:YES animated:YES];
[mpMoviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 768)];

[[globalSingleton paintingView] addSubview:mpMoviePlayerController.view];

[mpMoviePlayerController prepareToPlay];
[mpMoviePlayerController play];

mpMoviePlayerController.controlStyle = MPMovieControlStyleFullscreen;

或者这样..

    MPMoviePlayerController *mp;
MPMoviePlayerViewController *mpVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
mp = [mpVC moviePlayer];
mp.controlStyle = MPMovieControlStyleFullscreen;
mp.fullscreen = NO;
mp.useApplicationAudioSession = NO;
mp.view.frame = CGRectMake(0, 0, 1024, 768);

[[globalSingleton paintingView] addSubview:mp.view];

([globalSingleton paintingView]只是代表主视图,我已经检查过没有问题。)

请分享您对这个问题的了解。提前致谢!

最佳答案

根据您的代码,在我看来您的意图是让全屏电影播放器​​接管屏幕。在这种情况下,您可能最好使用 MPMoviePlayerViewController,但您需要使用当前的 View Controller 将其呈现为模态视图 Controller ,如下所示:

MPMoviePlayerViewController *movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:someVideoURL];
movieViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

// Self is the UIViewController you are presenting the movie player from.
[self presentMoviePlayerViewControllerAnimated:movieViewController];

“完成”按钮在这种情况下应该可以正常工作,并关闭模态 MPMoviePlayerViewController

另一方面,如果您对在当前 View 层次结构中添加电影的位置制作动画更感兴趣,这里是我为实现此目的所做的示例:

我还发现将 MPMoviePlayerController 的 controlStyle 属性设置为 MPMovieControlStyleFullscreen 会产生相同的结果——“完成”按钮不会关闭 MPMoviePlayerController。当我将其更改为 MPMovieControlStyleDefault 时,它按预期工作。但是,在我的例子中,我将 MPMoviePlayerController 的 View 作为缩略图大小的 subview 添加到当前显示的 UIViewController 的 View 中。我最初将 MPMoviePlayerController 的 controlStyle 设置为 MPMovieControlStyleNone。我在缩略图大小的电影播放器​​ View 顶部有一个自定义 UIButton,在按钮的操作方法中,我将 MPMoviePlayerController 的 controlStyle 更改为 MPMovieControlStyleDefault,然后调用 setFullscreen:animated: 将电影播放器​​ View 设置为全屏模式。然后,点击“完成”按钮以适当的方式将播放器动画化回我的 UIViewController View 的缩略图大小的 subview 中。这是一个例子:

我的 MPMoviePlayerController 的初始实例化:

// My moviePlayerController is a property
self.moviePlayer = [[MPMoviePlayerController alloc] initWithURL:videoURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.shouldAutoplay = NO;


// Add the moviePlayer's view as a subview of a my UIViewController's view.
moviePlayer.view.frame = CGRectMake(20, 20, 160, 90);
[self.view addSubview:moviePlayer.view];

注意:我还在我的 moviePlayer View 顶部添加了一个自定义 UIButton(以调用全屏播放)并将其设置为调用以下方法的操作:

- (void)buttonAction:(UIButton *)sender
{
self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
[self.moviePlayer setFullscreen:YES animated:YES];
[self.moviePlayer play];
}

注意:我还观察并处理了 MPMoviePlayerWillExitFullscreenNotification,我将 controlStyle 设置回 MPMovieControlStyleNone。

关于ios - "Done"MPMoviePlayerController 中的按钮在全屏模式下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11262009/

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