AVPlayer切换播放源与循环播放

AVPlayer切换播放源与循环播放


2024年1月4日发(作者:)

object:tItem]; }NSURL *sourceUrl = [NSURL fileURLWithPath:urlString];AVAsset *movieAsset = [AVAsset assetWithURL:sourceUrl];[movieAsset loadValuesAsynchronouslyForKeys:@[@"duration", @"tracks", @"commonMetadata"] completionHandler:^{dispatch_async(dispatch_get_main_queue(), ^{AVPlayerItem *playerItyem = [AVPlayerItem playerItemWithAsset:movieAsset];if (!) { = [AVPlayer playerWithPlayerItem:playerItyem];[ setActionAtItemEnd:AVPlayerActionAtItemEndPause];AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:]; = CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT);ravity = AVLayerVideoGravityResizeAspect;[ addSublayer:playerLayer];}else{//切换播放源,解决闪屏问题[ replaceCurrentItemWithPlayerItem:playerItyem];}//注册通知[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(runLoopTheMovie:)name:AVPlayerItemDidPlayToEndTimeNotification object:tItem];[ play];});}];}- (void)creatBaseView:(UIView *)view{if (!ew) {ew = [[UIView alloc] initWithFrame:];[view addSubview:_baseView];}

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resignActiveNotification)name:UIApplicationWillResignActiveNotification object:nil];}// 挂起- (void)resignActiveNotification{if () {[ pause];time = tTime;}positionImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)]; = [self captureCurrentScreen];[[[UIApplication sharedApplication] keyWindow] addSubview:positionImage];}// 结束挂起- (void)becomeActiveNotification{if () {@try {[ seekToTime:time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) {if (finished) {[ play];dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(),^{[positionImage removeFromSuperview];positionImage = nil;});}}];} @catch (NSException *exception) {[ play];dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(),


发布者:admin,转转请注明出处:http://www.yc00.com/web/1704327814a1341550.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信