MPMoviePlayerViewController 播放视频时显示效果不佳

发布于 2024-12-09 05:12:09 字数 1214 浏览 0 评论 0原文

我试图在我的应用程序上显示视频。该应用程序隐藏了 iPhone 顶部面板。该播放器似乎运行良好。只有一个烦人的问题:当播放器显示视频时,它有时显示顶部面板,有时隐藏它。当它被隐藏时,视频播放器面板会被推一点(与以前的面板大小相同)。是苹果的bug吗?我做错了什么吗? 这是我的代码:

- (void) showFullscreenMediaWithURL: (NSURL *) mediaURL
{
    MPMoviePlayerViewController *ctrl = [[MPMoviePlayerViewController alloc] initWithContentURL: mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:ctrl.moviePlayer];
    ctrl.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    ctrl.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [ctrl setWantsFullScreenLayout:YES];
    [self presentMoviePlayerViewControllerAnimated:ctrl];  
    [ctrl release];
}

-(void) playbackDidFinish:(NSNotification*)aNotification
{
   NSLog(@"Finished playback");  
   MPMoviePlayerController *player = [aNotification object];
   [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:player];
   [player stop];
   [self dismissMoviePlayerViewControllerAnimated];
   [[captureManager session] startRunning];

}

I trying to show video on my App. The App hides the iPhone top panel. The player seems to work fine. There is just one annoying problem: when the player shows the video, it sometimes show the top panel and sometime hides it. When it is hidden, the video player panel is pushed a little (the same size of the panel that used to be there). Is is Apple bug? Am I doing something wrong?
Here is my code:

- (void) showFullscreenMediaWithURL: (NSURL *) mediaURL
{
    MPMoviePlayerViewController *ctrl = [[MPMoviePlayerViewController alloc] initWithContentURL: mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:ctrl.moviePlayer];
    ctrl.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    ctrl.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [ctrl setWantsFullScreenLayout:YES];
    [self presentMoviePlayerViewControllerAnimated:ctrl];  
    [ctrl release];
}

-(void) playbackDidFinish:(NSNotification*)aNotification
{
   NSLog(@"Finished playback");  
   MPMoviePlayerController *player = [aNotification object];
   [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:player];
   [player stop];
   [self dismissMoviePlayerViewControllerAnimated];
   [[captureManager session] startRunning];

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ低調成傷 2024-12-16 05:12:09

如果您所说的 iPhone 顶部面板指的是 iPhone 状态栏,那么解决方案应该很简单。
在present/dismissMoviePlayerViewControllerAnimated之前添加以下内容:

// Hide Status Bar        
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
// Show Status Bar
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

更新:我可以看到您的问题所在。

首先,带有网络指示图标和其他信息的上方栏是 状态栏(没有其他内容)。您的问题似乎与 ViewController 相关,然后与 MediaPlayer 相关。换句话说,如果您尝试将其他一些 ViewController “推”到全屏(就像播放器一样),您将会遇到完全相同的问题。

其次,正确的方法,或者我可能会说:我首选的将视图控制器加载到全屏的方法如下:

  1. 设置一个全屏 rootViewController ,它将加载到 appDelegate 上的 applicationDidFinishLaunchingWithOptions 上。
  2. 在 rootViewController init 上放置您的默认 viewController(您用于从 appDelegate 加载的那个)。确保 rootViewController.view 的框架填满屏幕。
  3. 在 rootViewController 上创建 2 条消息:LoadFullscreen:viewController 和使用 Present/dismissModelViewController DismissFullscreen。 setStatusBarHidden 消息应该从这里调用。
  4. 要在全屏上播放播放器,请创建播放器 viewController 并执行 [rootViewController LoadFullscreen:player];

还有一些其他方法,但一般来说,这是最佳实践,也是我推荐的方法。实现起来相对“大量代码”,这就是为什么我无法帮助您使用代码片段,但总体思路相对简单。

我希望这有帮助,EG :)

if by iPhone top panel you mean the iPhone Status bar, then the solution should be simple.
Just before present/dismissMoviePlayerViewControllerAnimated add the following:

// Hide Status Bar        
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
// Show Status Bar
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

Update: I can see what seems to be your problem.

First, the upper bar with the network indication icons and other information is the status bar (and nothing else). Your problem seems to be more ViewController related then a MediaPlayer. In other words, If you would have try to "push" some other ViewController to full screen (as the player is) you would have experience the exact same issue.

Second, the proper way, or I might say: my preferred way, of loading a view controller to full screen is the following:

  1. Setup a full screen rootViewController which will be loaded on applicationDidFinishLaunchingWithOptions on your appDelegate.
  2. On the rootViewController init put your default viewController (the one you used to load from appDelegate). Make sure that the rootViewController.view's frame is filling the screen.
  3. Create 2 messages on rootViewController: LoadFullscreen:viewController and dismissFullscreen using present/dismissModelViewController. the setStatusBarHidden messages should be called from here.
  4. To Lunch the player on full screen, create the player viewController and perform [rootViewController LoadFullscreen:player];

There are some other ways, but generally, this is the best practice and the method I recommend. It's relatively "a lot of code" to implement, thats why I couldn't help you with code snippers, but the general idea is relatively simple.

I hope that's help, E.G :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文