WARNING: under normal conditions, _fillInQueueWithExtraSpace: ignoreExistingItems: should not be re-entered

This is my class that controlled my video:

#import "video.h" #import <MediaPlayer/MediaPlayer.h> @interface video() { MPMoviePlayerController* videoView; } @end @implementation video static video *sharedSingleton = nil; + (video *)sharedSingleton { @synchronized([video class]) { 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 

But sometimes I get this error when playing a video: WARNING: under normal conditions, _fillInQueueWithExtraSpace: ignoreExistingItems: should not be re-entered.

Where is the problem? Thank you in advance

I noticed one thing: the video freezes when you pass the time between stopping and playing. I fixed the error by leaving the video paused rather than paused.

+6
source share
1 answer

This is how I would structure your code

 @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 

If you are trying to play a video with a specific size in the parent view, see AVPlayer + AVPlayerLayer

0
source

Source: https://habr.com/ru/post/919333/


All Articles