[英]MPMoviePlayerController sometimes plays audio, not video when fading in
我有一個問題,在UIScrollView中,有許多視圖(下面的視頻控制器)充當視頻內容的頁面(最初顯示了縮略圖視圖)。
有時(但並非總是),當我滾動到下一頁時,視頻的音頻開始播放,但看不到任何視覺效果。 當我不淡入視圖時,似乎不會發生這種情況。
視頻初始化代碼為:
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init];
self.moviePlayer = moviePlayer;
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setRepeatMode:MPMovieRepeatModeOne];
[moviePlayer.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
moviePlayer.contentURL = [NSURL URLWithString:[videoData.video src]];
[self.videoController.view addSubview:self.moviePlayer.view];
[self.videoController.view bringSubviewToFront:moviePlayer.view];
[moviePlayer.view setAlpha:0.0f];
// Movie Observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkMovieStatus:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
// Add tap handler
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onPlayerTapped:)];
singleFingerTap.numberOfTapsRequired = 1;
singleFingerTap.delegate = self;
[self.moviePlayer.view addGestureRecognizer:singleFingerTap];
[moviePlayer prepareToPlay];
播放代碼(為避免在視頻開始時出現黑屏)是:
- (void)checkMovieStatus:(NSNotification *)notification {
if(self.moviePlayer.readyForDisplay && (MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK)) {
[self.moviePlayer play];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[UIView animateWithDuration:0.4f animations:^{
[self.moviePlayer.view setAlpha:1.0f];
} completion:^(BOOL finished) {
//[self.moviePlayer play]; // tried here as well
}];
}
}
刪除滾動上的視頻視圖的代碼是:
- (void)removeMoviePlayer {
if(self.moviePlayer) {
[self.moviePlayer stop];
[self.moviePlayer.view removeFromSuperview];
self.moviePlayer = nil;
}
}
我發現此問題的解決方法很奇怪。 以我為例,我將滑動至視頻,然后播放音頻,並且沒有圖片。 如果我輕掃一下再回來,一切都很好,所以只是為了好玩,我嘗試了
MPMoviePlayerController *mp = [self.arrayOfScrollView objectAtIndex:xx];
[mp play];
[mp stop];
[mp play];
奇怪的是。 自從您六個月前發布此文章以來,如果您發現了另一個解決方法,我很想知道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.