Looping AVPlayer seamlessly

后端 未结 4 2226
花落未央
花落未央 2020-11-29 09:51

There has been some discussion before about how to loop an AVPlayer\'s video item, but no \'solution\' is seamless enough to provide lag-less l

4条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 10:10

    I had the same problem when streaming a video. After playing for the first time, there was a black screen when loading the video for second time. I got rid of the black screen by seeking video to 5ms ahead. It made nearly a seamless video loop. (Swift 2.1)

    // Create player here..
    let player = AVPlayer(URL: videoURL)
    
    // Add notification block
    NSNotificationCenter.defaultCenter().addObserverForName(AVPlayerItemDidPlayToEndTimeNotification, object: player.currentItem, queue: nil)
    { notification in
       let t1 = CMTimeMake(5, 100);
       player.seekToTime(t1)
       player.play()
    }
    

提交回复
热议问题