问题
I have an iOS app in which I am trying to show videos using MPMoviePlayerController
.
The code is very simple and working fine on all the devices with all iOS version greater than 6.0.
But the problem is on iOS 8 and 8.1, the progress bar of the video is not visible as shown in below image.
I dont understand why this is happening or is this iOS 8 bug.
Please suggest. Thanks in advance.
回答1:
I had this issue too in my app, which supports several iOS versions but this issue is indeed only visible on iOS 8.
My code toggles the MPMoviePlayerController
's controlStyle
between MPMovieControlStyleEmbedded
and MPMovieControlStyleNone
, and this is triggered using UIDeviceOrientationDidChangeNotification
. I have to admit that I programmatically rotate my player, I do not rotate the application; this is maybe a root of this issue. I display the controls in portrait, and hide them in landscape.
I apparently solved it in two steps. I did not isolated this issue in a simple app so my apologies if the solution is not accurate for everyone.
First, the dirty part, and perhaps not necessary for everybody who encounter this issue, I parse some of the player subviews to look after the MPVideoPlaybackOverlayView
view, in order to force its visibility or invisibility.
// Helps to hide or show the controls over the player
// The reason of this method is we are programmatically rotating the player view, while not rotating the application
// On latest iOS, this leads to misbehavior that we have to take into account
-(void)showMPMoviePlayerControls:(BOOL)show
{
self.player.controlStyle = (show ? MPMovieControlStyleEmbedded : MPMovieControlStyleNone);
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8"))
{
// Workaround to avoid persistence of empty control bar
for(UIView *subView in self.player.backgroundView.superview.superview.subviews)
{
if ([subView isKindOfClass:NSClassFromString(@"MPVideoPlaybackOverlayView")]) {
subView.backgroundColor = [UIColor clearColor];
subView.alpha = (show ? 1.0 : 0.0);
subView.hidden = (show ? NO : YES);
}
}
}
}
But this was not enough. Probably because the portrait mode has several orientations (UIDeviceOrientationPortrait
, UIDeviceOrientationFaceUp
, ...) that trigger the notification, hence the control style change request.
So the second step of my fix was to handle the fact that it is not necessary to change the MPMoviePlayerController
's controlStyle
if we are already in the correct screen orientation.
In my case, the solution was to verify that the status bar was hidden, as I hide it in landscape:
// Set embedded controls only when there is a transition to portrait, i.e. if status bar was hidden
if ([[UIApplication sharedApplication] isStatusBarHidden]) {
[self showMPMoviePlayerControls:YES];
// and we show the status bar here
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
Maybe the point here is that we should not set the controlStyle
if it is already set to the wanted value.
As this solved the problem for me, I stopped my investigations. Anyway I suppose that it is probably simpler in most cases. Certainly linked to the fact that the controlStyle
is changed at the wrong time, or changed but was already in the wanted state.
来源:https://stackoverflow.com/questions/27925227/ios-8-video-progress-bar-not-visible