警告:在正常条件下,_fillInQueueWithExtraSpace:ignoreExistin

2019-09-18 19:09发布

这是我的类,管理我的视频:

#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

警告:但有时播放视频时,我得到这个错误,在正常情况下,_fillInQueueWithExtraSpace:ignoreExistingItems:不应该被重新输入。

问题出在哪儿? 先感谢您

我注意到一两件事:当你通过停止和播放之间的实时视频冻结。 我固定的错误离开视频停顿了一下,没有停止过。

Answer 1:

下面是我会怎样构建你的代码

@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

如果你想在一个父视图中具有一定规模,以播放视频,看AVPlayer + AVPlayerLayer



文章来源: WARNING: under normal conditions, _fillInQueueWithExtraSpace:ignoreExistingItems: should not be re-entered