警告:在正常情况下,_fillInQueueWithExtraSpace:ignoreExistingItems:不应该被重新input

这是我的class级pipe理我的video:

#import "video.h" #import <MediaPlayer/MediaPlayer.h> @interface video() { MPMoviePlayerController* videoView; } @end @implementation video static video *sharedSingleton = nil; + (video *)sharedSingleton { @synchronized() { if (!sharedSingleton) sharedSingleton = [[super allocWithZone:NULL] init]; return sharedSingleton; } return nil; } - (id)init { self = [super init]; CGRect dimVideo = CGRectMake(0, 0, 472, 400); NSURL* videoPath = [[NSBundle mainBundle] URLForResource: @"videoName" withExtension: @"mp4"]; self->videoView = [[MPMoviePlayerController alloc] initWithContentURL:videoPath]; [self->videoView.view setFrame:dimVideo]; [self->videoView prepareToPlay]; return self; } - (void)addVideoOn:(UIView*)view{ [view addSubview:self->videoView.view]; [self->videoView play]; } - (void)removeVideo{ [self->videoView stop]; [self->videoView.view removeFromSuperview]; } @end 

但是有时播放video的时候会出现这个错误:警告:在正常情况下,_fillInQueueWithExtraSpace:ignoreExistingItems:不应该被重新input。

哪里有问题? 先谢谢你

我注意到一件事:当你在停止和播放之间传递时间时,video会冻结。 我修复了错误,使video暂停,不停止。

以下是我将如何构build您的代码

 @interface Video : NSObject @property ( nonatomic, strong, readonly ) MPMoviePlayerController * videoView ; @end @implementation Video @synthesize videoView = _videoView ; +(Video *)sharedSingleton { static Video * __sharedSingleton ; static dispatch_once_t once ; dispatch_once( &once, ^{ __sharedSingleton = [ [ [ self class ] alloc ] init ] ; } return __sharedSingleton ; } -(void)dealloc { [ _videoView stop ] ; [ _videoView.view removeFromSuperview ] ; } -(void)ensureMoviePlayer { if (!_videoView ) { NSURL* url = [[NSBundle mainBundle] URLForResource:@"videoName" withExtension:@"mp4"]; _videoView = [[MPMoviePlayerController alloc] initWithContentURL:url]; } } - (void)addVideoOn:(UIView*)view { [ self ensureMoviePlayer ] ; self.videoView.view.frame = view.bounds ; // per documentation [view addSubview:self.videoView.view]; [self.videoView play]; } - (void)removeVideo { [self.videoView stop]; [ self.videoView.view removeFromSuperview ] ; } @end 

如果您想在父视图中以特定尺寸播放video,请查看AVPlayer + AVPlayerLayer