警告:在正常情况下,_fillInQueueWithExtraSpace:ignoreExistingItems:不应重新输入 [英] WARNING: under normal conditions, _fillInQueueWithExtraSpace:ignoreExistingItems: should not be re-entered
问题描述
这是我管理视频的课程:
This is my class that managed 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
但有时我会收到此错误播放视频时:
警告:在正常情况下,_fillInQueueWithExtraSpace:ignoreExistingItems:不应重新输入。
But sometimes I get this error when play the video: WARNING: under normal conditions, _fillInQueueWithExtraSpace:ignoreExistingItems: should not be re-entered.
问题出在哪里?
提前谢谢
Where is the problem? Thank you in advance
我注意到一件事:
视频在停止和播放之间经过时间时冻结。
我修正了错误,让视频暂停,而不是停止。
I noticed one thing: video freezes when you pass the time between the stop and play. I fixed the error leaving the video paused, not stopped.
推荐答案
以下是我构建代码的方法
Here's 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
如果你正在尝试g要在父视图中播放一定大小的视频,请查看 AVPlayer
+ AVPlayerLayer
If you're trying to play video at a certain size within a parent view, look at AVPlayer
+ AVPlayerLayer
这篇关于警告:在正常情况下,_fillInQueueWithExtraSpace:ignoreExistingItems:不应重新输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!