这是我管理我的视频的课程:
#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: 不应重新输入。
问题出在哪里?先感谢您
我注意到一件事:当您在停止和播放之间经过时间时,视频会冻结。我修复了让视频暂停而不是停止的错误。