Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 警告:在正常情况下,不应重新输入\u fillInQueueWithExtraSpace:ignoreExistingItems:_Ios_Video_Mpmovieplayercontroller_Avfoundation - Fatal编程技术网

Ios 警告:在正常情况下,不应重新输入\u fillInQueueWithExtraSpace:ignoreExistingItems:

Ios 警告:在正常情况下,不应重新输入\u fillInQueueWithExtraSpace:ignoreExistingItems:,ios,video,mpmovieplayercontroller,avfoundation,Ios,Video,Mpmovieplayercontroller,Avfoundation,这是我管理视频的班级: #import "video.h" #import <MediaPlayer/MediaPlayer.h> @interface video() { MPMoviePlayerController* videoView; } @end @implementation video static video *sharedSingleton = nil; + (video *)sharedSingleton { @synchronized(

这是我管理视频的班级:

#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
#导入“video.h”
#进口
@接口视频()
{
MPMoviePlayerController*视频视图;
}
@结束
@实施视频
静态视频*sharedSingleton=nil;
+(视频*)共享辛格尔顿
{
@已同步([视频类])
{
如果(!sharedSingleton)
sharedSingleton=[[super allocWithZone:NULL]init];
返回共享辛格尔顿;
}
返回零;
}
-(id)init
{
self=[super init];
CGRect dimVideo=CGRectMake(0,0472400);
NSURL*videoPath=[[NSBundle mainBundle]URLForResource:@“videoName”,扩展名:@“mp4”];
self->videoView=[[MPMoviePlayerController alloc]initWithContentURL:videoPath];
[self->videoView.view设置帧:dimVideo];
[自我->视频查看准备播放];
回归自我;
}
-(void)addvideon:(UIView*)视图{
[查看添加子视图:self->videoView.view];
[self->videoView play];
}
-(无效)删除视频{
[自->视频查看停止];
[self->videoView.view从SuperView移除];
}
@结束
但有时我在播放视频时会出现以下错误: 警告:在正常情况下,不应重新输入\u fillInQueueWithExtraSpace:ignoreExistingItems:

问题在哪里? 先谢谢你

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

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

@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

通常将类名大写:“video”而不是“video”此外,如果
MPMoviePlayerController
的文档中说“播放器的帧必须与家长的帧匹配”,那么无论出于什么原因,
-init
中的
MPMoviePlayerController
都会崩溃,这与您的代码不同。我会试着先把它修好。