Ios 从本地目录多次播放视频后,AVPlayer崩溃
当我单击我的本地视频url并显示Viewcontroller并在AVPlayer中播放视频时。播放14-15次,播放器崩溃Ios 从本地目录多次播放视频后,AVPlayer崩溃,ios,objective-c,video,avplayer,avplayerviewcontroller,Ios,Objective C,Video,Avplayer,Avplayerviewcontroller,当我单击我的本地视频url并显示Viewcontroller并在AVPlayer中播放视频时。播放14-15次,播放器崩溃 谁有解决办法。?请帮帮我。谢谢您是否设置了所有时间的AvPlayerWebController框架?是的,avPlayer=[avPlayer playerWithURL:fileURL];Avcontroller=[[avplayervewcontroller alloc]init];Avcontroller.player=avPlayer;Avcontroller.vi
谁有解决办法。?请帮帮我。谢谢您是否设置了所有时间的AvPlayerWebController框架?是的,avPlayer=[avPlayer playerWithURL:fileURL];Avcontroller=[[avplayervewcontroller alloc]init];Avcontroller.player=avPlayer;Avcontroller.view.frame=self.view.frame;Avcontroller.videoGravity=AVLayerVideoGravityResizeAspectFill;[self.view addSubview:_Avcontroller.view];Brother显示完整代码亲爱的,这是完整代码,单击url直接显示viewcontroller和player[self.view addSubview:_Avcontroller.view];然后开始。请参考此答案
- (void)viewDidLoad
{
[self PlayVideoinPlayer:_videoURL];
}
-(void)PlayVideoinPlayer:(NSString *)URL
{
NSURL *fileURL = [NSURL fileURLWithPath:URL];
_Avcontroller=[[AVPlayerViewController alloc]init];
asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
anItem = [AVPlayerItem playerItemWithAsset:asset];
_avPlayer = [AVPlayer playerWithPlayerItem:anItem];
[_avPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
self.Avcontroller.view.frame = self.view.bounds;
[self.Avcontroller setPlayer:_avPlayer];
_Avcontroller.videoGravity=AVLayerVideoGravityResizeAspectFill;
[self.view addSubview:self.Avcontroller.view];
[self.view addSubview:self.Avcontroller.view];
[_avPlayer play];
CMTime interval = CMTimeMake(1, 1800);
__strong __typeof(self) weakself = self;
playbackObserver = [_avPlayer addPeriodicTimeObserverForInterval:interval queue:dispatch_get_main_queue() usingBlock: ^(CMTime time) {
CMTime endTime = CMTimeConvertScale (_avPlayer.currentItem.asset.duration, _avPlayer.currentTime.timescale, kCMTimeRoundingMethod_RoundHalfAwayFromZero);
if (CMTimeCompare(endTime, kCMTimeZero) != 0)
{
// double normalizedTime = (double) avPlayer.currentTime.value / (double) endTime.value;
//NSLog(@"--------->>>>%@",playbackObserver);
}
int CurrentSecond=[[weakself getStringFromCMTime:_avPlayer.currentTime] intValue];
_avPlayer.rate=1.0f;
}