我想使用AVPlayerController播放视频的特定部分。但不知道怎么玩。这是我的密码

func playVideoMethod(path:URL) {

    avpController = AVPlayerViewController()
    avpController.player = AVPlayer.init(url: path)
    avpController.view.frame = self.playerView.bounds
    avpController.showsPlaybackControls = false
    let translate = CGAffineTransform(rotationAngle: CGFloat(Int(M_PI/18.0)))
    avpController.view.transform = translate
    self.playerView.addSubview(avpController.view)
    self.playerView.autoresizesSubviews = true
    avpController.player?.play()
}

最佳答案

您可以对代码进行以下修改:

let item = AVPlayerItem(url: path)
let player = AVPlayer(playerItem: item)
player.seek(to: CMTime(... // add time what you want to start from
item.forwardPlaybackEndTime = CMTime(... // add preferred end time
avpController.player = player

08-19 12:33