gpt4 book ai didi

ios - 警告 : under normal conditions, _fillInQueueWithExtraSpace:ignoreExistingItems: 不应重新输入

转载 作者:可可西里 更新时间:2023-11-01 04:03:31 27 4
gpt4 key购买 nike

这是管理我的视频的类(class):

#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:。

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

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

最佳答案

这是我将如何构建您的代码

@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

如果您尝试在父 View 中以特定大小播放视频,请查看 AVPlayer + AVPlayerLayer

关于ios - 警告 : under normal conditions, _fillInQueueWithExtraSpace:ignoreExistingItems: 不应重新输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11263323/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com