Ok, so here's the thing. I have a UIViewController that contains a UITabBarController. That tab bar has a UIViewController for each tab button. Now, inside one of the tab buttons is an MPMoviePlayerController 开发者_Go百科that is playing a stream from over the network. Playing the stream works just fine and you can see the video and hear the audio.
The problem is when you navigate to another tab. The audio still plays, which is good, but when you go back to the stream, the video is black. The audio is still playing, but the video needs to be playing too.
Has anyone run into this problem before?
I'm currently using iOS 4.0 to build against and an iPhone 3GS.
If more information is needed, just ask and I'll do my best to answer.
Thanks, Robbie
Strange things might happen if the view isn't on-screen (I believe it's removed from the view hierarchy when you switch tabs).
- Have you tried using MPMoviePlayer's view directly? (not MPMoviePlayerController)
- Can you add and remove the view and keep the movie playing?
- Does pausing and resuming help?
- Could you pass the view around between view controllers, or maybe make it a direct subview of the window in viewWillDisappear and move it back in viewDidAppear? (I'm not sure if the view's been removed from the hierarchy in viewWillAppear/viewDidDisappear.)
The solution I'm going ahead with is entering fullscreen mode and exiting fullscreen mode very quickly. It may not be the best thing, but it's working.
This still happens on iOS 6. If I have two movie player (one on each tab), even if they are not playing, if I switch form the first to the seconds tab and return to the first, the movie player will be black.
My solution was as simple as calling prepareToPlay
on -viewDidAppear:
:
- (void)viewDidAppear:(BOOL)animated;
{
[super viewDidAppear:animated];
[self.moviePlayer prepareToPlay];
}
I believe this will add the shared internal view of MPMoviePlayerController
to the view hierarchy.
精彩评论