如何在Swift3 iOS中的特定时间段内在AVPlayer中播放视频 [英] How to Play a video in AVPlayer for a specific duration in Swift3 iOS
问题描述
我正在Swift3
中创建一个Video
应用程序.在TableView
列表中的Video
文件列表中.对于每个Video
,我们提供了Range Slider
选项供用户选择Video
中的Range
.现在,我尝试播放由用户选择的特定范围的Video
.
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.
我正在使用以下代码从4开始Video
使用CMTimeMake
秒到8秒,但不能正确播放.
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.
推荐答案
也许试试看:
let item = AVPlayerItem(url: path)
let player = AVPlayer(playerItem: item)
player.seek(to: CMTimeMake(4, 1))
item.forwardPlaybackEndTime = CMTimeMake(8, 1)
self.player.play()
这看上去与原始代码非常相似,只是使用了.currentItem
,我猜这可能是问题所在.
This looks pretty similar to the original code, minus the use of .currentItem
which I'm guessing might be the issue.
这篇关于如何在Swift3 iOS中的特定时间段内在AVPlayer中播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!