玩家正在播放内容,但不能完全显示
我需要明智地更改代码
代码库
NSLog(@"playerURL %@",self->playerURL);
if ((([self->playerURL rangeOfString:@".ts"].location == NSNotFound && [self->playerURL rangeOfString:@".mpd"].location == NSNotFound))) {
self->isFailed=false;
self->isCustomViewShowing=false;
NSMutableDictionary * headers = [NSMutableDictionary dictionary];
[headers setObject:@"EvueNowMobilePadApplication" forKey:@"User-Agent"];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:self->playerURL] options:@{@"AVURLAssetHTTPHeaderFieldsKey" : headers}];
AVAssetResourceLoader *loader = [asset resourceLoader];
[loader setDelegate:self queue:dispatch_get_main_queue()];
self->playerItem =[AVPlayerItem playerItemWithAsset:asset];
AVPlayer* videoPlayer=[[AVPlayer alloc]initWithPlayerItem:self->playerItem];
self.player=videoPlayer;
self.showsPlaybackControls=NO;
self.player.appliesMediaSelectionCriteriaAutomatically=FALSE;
BOOL ccEnable= [[NSUserDefaults standardUserDefaults] boolForKey:@"closedCaptionStatus"];
[self.player setClosedCaptionDisplayEnabled:ccEnable];
[self.player replaceCurrentItemWithPlayerItem:self->playerItem];
// [self.player seekToTime:CMTimeMake(self->seekValue, 1)];
[self.player play];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playerItemDidReachEnd:)name:AVPlayerItemDidPlayToEndTimeNotification object:[self.player currentItem]];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playerItemDidFail:)name:AVPlayerItemFailedToPlayToEndTimeNotification object:[self.player currentItem]];
[self.player.currentItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionPrior context:nil];
//
// [self.player addObserver:self forKeyPath:@"rate" options:0 context:nil];
//
[self.player.currentItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
CMTime duration = self.player.currentItem.asset.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %f", seconds);
// [self.player.currentItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuBtnSelectedInEASPlayer:)];
tapGesture.allowedPressTypes = @[@(UIPressTypeMenu)];
[self.view addGestureRecognizer:tapGesture];
}
else{
self->isFailed=true;
}
});
isCustomViewShowing=true;
}