解决mpmovieplayercontroller左上角蓝色不明区块问题

最近在做的应用里面需要动态放大缩小视频窗口,使用[MPMoviePlayerController]作为播放器。

使用如下代码造成放大情况下,在视频左上角出现不明蓝色‘物体’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
if (self.videoViewMode == kBookPageContentViewControllerVideoViewModeCircle) {
self.videoViewMode = kBookPageContentViewControllerVideoViewModeFullScreen;
self.videoViewPlaceholderWidth.constant = self.view.width;
self.videoViewPlaceholderHeight.constant = self.view.height;
self.videoViewPlaceHolderXOffset.constant = 0;
self.videoViewPlaceHolderYOffset.constant = 0;
[UIView animateWithDuration:1 animations:^{
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
self.videoView.layer.cornerRadius = 0;
self.videoView.clipsToBounds = NO;
[self.view layoutIfNeeded];
}];
} else {
self.videoViewMode = kBookPageContentViewControllerVideoViewModeCircle;
self.videoViewPlaceholderHeight.constant = kVideoViewHeightWidth;
self.videoViewPlaceholderWidth.constant = kVideoViewHeightWidth;
self.videoViewPlaceHolderXOffset.constant = arc4random_uniform(self.view.width * 0.2) - kVideoViewHeightWidth;
self.videoViewPlaceHolderYOffset.constant = kVideoViewHeightWidth - arc4random_uniform(self.view.height * 0.2);
[UIView animateWithDuration:1 animations:^{
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
self.videoView.layer.cornerRadius = kVideoViewHeightWidth * 0.5;
self.videoView.clipsToBounds = YES;
[self.view layoutIfNeeded];
}];
}
}

经检查

1
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill

不能放在动画block里面,移出即可解决该问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
if (self.videoViewMode == kBookPageContentViewControllerVideoViewModeCircle) {
self.videoViewMode = kBookPageContentViewControllerVideoViewModeFullScreen;
self.videoViewPlaceholderWidth.constant = self.view.width;
self.videoViewPlaceholderHeight.constant = self.view.height;
self.videoViewPlaceHolderXOffset.constant = 0;
self.videoViewPlaceHolderYOffset.constant = 0;
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[UIView animateWithDuration:1 animations:^{
self.videoView.layer.cornerRadius = 0;
self.videoView.clipsToBounds = NO;
[self.view layoutIfNeeded];
}];
} else {
self.videoViewMode = kBookPageContentViewControllerVideoViewModeCircle;
self.videoViewPlaceholderHeight.constant = kVideoViewHeightWidth;
self.videoViewPlaceholderWidth.constant = kVideoViewHeightWidth;
self.videoViewPlaceHolderXOffset.constant = arc4random_uniform(self.view.width * 0.2) - kVideoViewHeightWidth;
self.videoViewPlaceHolderYOffset.constant = kVideoViewHeightWidth - arc4random_uniform(self.view.height * 0.2);
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[UIView animateWithDuration:1 animations:^{
self.videoView.layer.cornerRadius = kVideoViewHeightWidth * 0.5;
self.videoView.clipsToBounds = YES;
[self.view layoutIfNeeded];
}];
}
}