问题
I am creating a Video application in Swift3. Where we have a list of Video files in a TableView list. For each Video we have given Range Slider option for user to select Range of the Video. Now I am trying to play the Video for that specific range, selected by the User.
I am using below code to start a Video from 4
Seconds to 8 Seconds using CMTimeMake but not playing correctly.
let targetTime:CMTime = CMTimeMake(4, 1)////Video start
self.player?.seek(to: targetTime)
self.player?.currentItem?.forwardPlaybackEndTime = CMTimeMake(8, 1)//Video stop
self.player?.play()
Can anyone help me where I am doing wrong. Thank you.
回答1:
Maybe try this:
let item = AVPlayerItem(url: path)
let player = AVPlayer(playerItem: item)
player.seek(to: CMTimeMake(4, 1))
item.forwardPlaybackEndTime = CMTimeMake(8, 1)
self.player.play()
Edit: This looks pretty similar to the original code, minus the use of .currentItem which I'm guessing might be the issue.
来源:https://stackoverflow.com/questions/50810183/how-to-play-a-video-in-avplayer-for-a-specific-duration-in-swift3-ios