【问题标题】:WARNING: under normal conditions, _fillInQueueWithExtraSpace:ignoreExistingItems: should not be re-entered警告:在正常情况下,_fillInQueueWithExtraSpace:ignoreExistingItems: 不应重新输入
【发布时间】:2012-06-29 14:08:04
【问题描述】:

这是管理我的视频的班级:

#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: 不应重新输入。

问题出在哪里? 提前谢谢你

我注意到一件事: 当您通过停止和播放之间的时间时,视频会冻结。 我修复了让视频暂停而不是停止的错误。

【问题讨论】:

  • 类名大写是惯例:“Video”而不是“video”
  • 如果self == nil 在-init 中无论出于何种原因,这也会崩溃
  • MPMoviePlayerController 的文档说“玩家的框架必须与父母的框架相匹配”,而您的代码并非如此。我会先尝试解决这个问题。

标签: ios video mpmovieplayercontroller avfoundation


【解决方案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

【讨论】:

    猜你喜欢
    • 2011-03-23
    • 2023-03-06
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2020-10-21
    • 2014-05-08
    相关资源
    最近更新 更多