美文网首页
iOS-AVPlayer循环播放

iOS-AVPlayer循环播放

作者: 鱼与熊掌不能兼得 | 来源:发表于2017-11-07 14:09 被阅读116次

    AVPlayerItem*videoItem = [[AVPlayerItemalloc] initWithURL:pathUrl];

    AVPlayer*player = [AVPlayerplayerWithPlayerItem:videoItem];

    player.volume =0;

    AVPlayerLayer*playerLayer = [AVPlayerLayerplayerLayerWithPlayer:player];

    playerLayer.backgroundColor = [UIColorwhiteColor].CGColor;

    playerLayer.videoGravity =AVLayerVideoGravityResizeAspectFill;

    playerLayer.frame =self.view.bounds;

    [self.view.layer insertSublayer:playerLayer atIndex:0];

    [player play];

    self.player = player;

    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(moviePlayDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotificationobject:self.player.currentItem];

    - (void)dealloc {

    [[NSNotificationCenterdefaultCenter] removeObserver:self];

    }

    // 视频循环播放

    - (void)moviePlayDidEnd:(NSNotification*)notification{

    AVPlayerItem*item = [notification object];

    [item seekToTime:kCMTimeZero];

    [self.player play];

    }

    相关文章

      网友评论

          本文标题:iOS-AVPlayer循环播放

          本文链接:https://www.haomeiwen.com/subject/lccjmxtx.html