gpt4 book ai didi

iphone - 如何在播放 MPMoviePlayerController 电影之前隐藏控件?

转载 作者:行者123 更新时间:2023-12-03 18:19:19 26 4
gpt4 key购买 nike

假设使用 iOS 3.2 或更高版本。在最初隐藏控件的情况下执行 Action 的正确命令顺序是什么?电影播放时,用户可以选择在屏幕上标记并显示控件。

谢谢!

我的(控件未隐藏)代码:

- (void)playMovie
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Test" ofType:@"m4v"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieState:)
name:MPMoviePlayerNowPlayingMovieDidChangeNotification
object:moviePlayer];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieReady:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];


if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
moviePlayer.controlStyle = MPMovieControlStyleDefault; // MPMovieControlStyleNone MPMovieControlStyleEmbedded MPMovieControlStyleFullscreen MPMovieControlStyleDefault
moviePlayer.scalingMode = MPMovieScalingModeAspectFill; // MPMovieScalingModeAspectFit MPMovieScalingModeAspectFill
}
}

- (void) movieReady:(NSNotification*)notification
{
MPMoviePlayerController *moviePlayer = [notification object];

if ([moviePlayer loadState] != MPMovieLoadStateUnknown) {
// Remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];

// When tapping movie, status bar will appear, it shows up
// in portrait mode by default. Set orientation to landscape
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

// Add movie player as subview
[[self view] addSubview:[moviePlayer view]];

// Play the movie
[moviePlayer play];
[moviePlayer setFullscreen:YES animated:YES];
}
}

最佳答案

[更新] 正如 @ReinYem 所提议的,更好的解决方案是依赖 MPMoviePlayerLoadStateDidChangeNotification 而不是计时器。

实际上,不应该再考虑下面的解决方案:

最初将 controlStyle 属性设置为 MPMovieControlStyleNone,然后在一秒后使用 [performSelector:withObject: 将其设置为 MPMovieControlStyleFullscreen afterDelay:1]。它运行良好,直到用户点击视频后控件才会出现。

关于iphone - 如何在播放 MPMoviePlayerController 电影之前隐藏控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3961137/

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