播放按钮和电影放映之间的延迟

发布于 2024-09-26 23:02:57 字数 375 浏览 7 评论 0原文

我有一个简单的视图,当用户按下按钮时,使用 PresentMoviePlayerViewControllerAnimated: 方法创建 MPMoviePlayerViewController。新的视图控制器滑入并显示电影播放器​​,到目前为止一切顺利。

但是,当按下按钮时,当前视图控制器会滑出底部,显示丑陋的(可能是默认的)白色视图,该视图会在任何地方停留半秒到几秒,直到显示电影视图控制器。看起来它依赖于我的网络连接,就好像电影视图控制器在显示播放器之前下载电影的部分内容一样。

我做错了什么吗,或者我该如何解决这个问题?我真的更喜欢直接显示电影视图控制器,甚至可能不需要滑出之前保存播放按钮的视图控制器,但仍然像模态视图控制器一样进行动画处理。

谢谢!

克里斯托夫

I have a simple view that creates a MPMoviePlayerViewController when the user presses a button, using the presentMoviePlayerViewControllerAnimated: method. The new view controller slides in and shows the movie player, so far so good.

However, when the button is pushed, the current view controller slides out the bottom, showing a ugly (probably default) white view, that sticks around anywhere from half a second to a few seconds, until the movie view controller is shown. It seems like it's dependent on my network connection, as if the movie view controller is downloading parts of the movie before showing the player.

Am I doing something wrong, or how can I work around this? I'd really prefer to just show the movie view controller directly, maybe even without sliding out the previous view controller that holds the play button, but still animated like a modal view controller.

Thanks!

Christoph

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

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

发布评论

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

评论(4

錯遇了你 2024-10-03 23:02:57

解决方案是在创建父视图时初始化播放器视图控制器,然后在其中的 moviePlayer 上调用 prepareToPlay 。这消除了按下播放按钮时的延迟,并且(我猜)将其移动到用户到达可以播放电影的父视图时。

编辑:
这消除了延迟,但由于某种原因,初始化电影视图控制器也会在加载时自动播放它,所以这不是一个好的解决方案。

The solution was to init the player view controller when the parent view is created, and then call prepareToPlay on the moviePlayer inside it. That removes the latency when the play button is pushed and (I guess) moves it to when the user gets to the parent view from which he can play the movie.

EDIT:
This removes the delay, but for some reason, initializing the movie view controller also autoplays it when it's loaded, so that's not a good solution.

谁把谁当真 2024-10-03 23:02:57

我最终只是将视图的背景设置为黑色。不修复延迟,但使其看起来更好:

  theMovieVC.view.backgroundColor = [UIColor blackColor];

I ended up just setting the background of the view to black. Doesn't fix the delay, but makes it look much nicer:

  theMovieVC.view.backgroundColor = [UIColor blackColor];
那请放手 2024-10-03 23:02:57

这就是我为 iOS 所做的> 3.2 :

- (void) play {
    mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:mMovieURL];

    if ([mMoviePlayer respondsToSelector:@selector(loadState)]) 
    {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePreloadDidFinishIOS32:) 
                                                     name:MPMoviePlayerContentPreloadDidFinishNotification 
                                                   object:nil];


        [mMoviePlayer prepareToPlay];
        [mMoviePlayer play];
        mMoviePlayer.controlStyle = MPMovieControlStyleEmbedded;
        [mMoviePlayer setMovieControlMode:MPMovieControlModeDefault];
        [mMoviePlayer setBackgroundColor:[UIColor clearColor]];
    }
}

因此

- (void) moviePreloadDidFinishIOS32:(NSNotification*)notification;
{
    // Remove observer
    [[NSNotificationCenter  defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerContentPreloadDidFinishNotification
     object:nil];

    self.view = mMoviePlayer.view;
}

,在 viewdidload 中,您可以实例化您想要的内容(例如 UIActivityIndi​​catorView)。仅当预加载完成后,视图控制器才会被替换。

this is what i do for iOS > 3.2 :

- (void) play {
    mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:mMovieURL];

    if ([mMoviePlayer respondsToSelector:@selector(loadState)]) 
    {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePreloadDidFinishIOS32:) 
                                                     name:MPMoviePlayerContentPreloadDidFinishNotification 
                                                   object:nil];


        [mMoviePlayer prepareToPlay];
        [mMoviePlayer play];
        mMoviePlayer.controlStyle = MPMovieControlStyleEmbedded;
        [mMoviePlayer setMovieControlMode:MPMovieControlModeDefault];
        [mMoviePlayer setBackgroundColor:[UIColor clearColor]];
    }
}

and

- (void) moviePreloadDidFinishIOS32:(NSNotification*)notification;
{
    // Remove observer
    [[NSNotificationCenter  defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerContentPreloadDidFinishNotification
     object:nil];

    self.view = mMoviePlayer.view;
}

Thus in the viewdidload you can instantiate what you want (UIActivityIndicatorView for example). The view controller will only be replaced when the preload is finished.

鸠书 2024-10-03 23:02:57

我在我的应用程序中注意到同样的问题。有人有避免这个问题的建议吗?

就我而言,我将 MPMoviePlayerViewController 作为模式弹出窗口推送到 UI。

// build the movie player
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
MPMoviePlayerViewController *movieViewController = [[[MPMoviePlayerViewController alloc] initWithContentURL:request.URL] autorelease];
[movieViewController.moviePlayer prepareToPlay];
movieViewController.view.backgroundColor = [UIColor blackColor];

// show the movie player view
[self.parentViewController presentModalViewController:movieViewController animated:YES];

I'm noticing the same issue in my app. Anyone have suggestions to avoid this issue?

In my case, I'm pushing the MPMoviePlayerViewController to the UI as a modal popup.

// build the movie player
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
MPMoviePlayerViewController *movieViewController = [[[MPMoviePlayerViewController alloc] initWithContentURL:request.URL] autorelease];
[movieViewController.moviePlayer prepareToPlay];
movieViewController.view.backgroundColor = [UIColor blackColor];

// show the movie player view
[self.parentViewController presentModalViewController:movieViewController animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文