gpt4 book ai didi

iphone - iPad 3.2 & [MPMoviePlayerController setFullScreen :] not showing up

转载 作者:行者123 更新时间:2023-11-29 05:05:21 26 4
gpt4 key购买 nike

我有一个通用应用程序,可以播放互联网上的电影。它必须支持 3.1.x 和 4.x。

为了使其正常工作,我在代码中设置了一个分支,用于检测 3.2 之前的设备并利用 MPMoviePlayerController,因为它应该在那里工作。

这是我准备播放器播放远程电影的方法:

- (void)registerForMovieNotifications {
//for 3.2 devices and above
if ([moviePlayer respondsToSelector:@selector(loadState)]) {
LOG(@"moviePlayer responds to loadState, this is a 3.2+ device");

//register the notification that the movie is ready to play
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didExitFullScreen:)
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];

LOG(@"preparing moviePlayer...");
[moviePlayer prepareToPlay];



} else {
//for pre-3.2 devices
LOG(@"This is a 3.1.x device");

//register the notification that the movie is ready to play
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
}

//handle when the movie finished
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
- (void)readyPlayer {
if (!moviePlayer) {
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
} else {
[moviePlayer setContentURL:movieURL];
}

[self registerForMovieNotifications];
}

稍后我收到此通知,它会设置电影播放器​​的 View 等。

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification {
LOG(@"3.2/4.x - moviePlayerLoadStateChanged:");
//unless state is unknown, start playback
if ([moviePlayer loadState] != MPMovieLoadStateUnknown) {
//remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];

//set the frame of the movie player to match
self.view.autoresizesSubviews = YES;

[[moviePlayer view] setFrame:self.view.bounds];
[[moviePlayer view] setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[moviePlayer view] setAutoresizesSubviews:YES];

//add movie player as a subview
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES];

//play the movie
[moviePlayer play];

}
}

电影开始播放。这在 iPhone 4.2、4.3、iPad 4.2、4.3 上完美运行,但在 iPad 3.2 上失败。电影正在播放,但我看到的只是黑屏。

如果我删除 [moviePlayer setFullscreen:YES] 调用,我会在 3.2 中看到一个可见的正在播放的电影,但它不是“全屏”,因此它没有“完成”按钮,并且有我无法关闭屏幕。

希望能得到一些关于这里发生的事情的帮助。谢谢!

最佳答案

我能够找到一个可接受的解决方案,但我仍然觉得这可能是一个错误。

如果我跳过对 setFullScreen 的调用,而只是手动将 controlStyle 设置为 MPMovieControlStyleFullScreen 那么它会给我一个基本正确的 View (工具栏大约低了 40 像素)。

然后我可以获得“完成”按钮,该按钮会触发 moviePlayer:didFinishPlaying 回调。

所以这很糟糕,我的代码中现在有一个臭味的 if 3.2 逻辑分支,但希望大多数人无论如何都会使用 4.0。

关于iphone - iPad 3.2 & [MPMoviePlayerController setFullScreen :] not showing up,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5629079/

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