簡體   English   中英

獲取AVPlayer ios中當前播放視頻的時間

[英]Get current time of video playing in AVPlayer ios

當我使用AVPlayer播放視頻時,我無法在視頻開始播放時獲得當前項目。 我使用下面的代碼來獲取當前時間。 請幫我解決以下問題。 提前致謝

let item1 = AVPlayerItem.init(URL: NSURL(string:path))
let player = AVPlayer(playerItem: item1)

layer?.player = player;
player?.play

let currentItem:AVPlayerItem = player!.currentItem
let currentTime:NSTimeInterval = CMTimeGetSeconds(currentItem.currentTime())

您可以將其更改為Int,Double或Float。 無論你喜歡什么。

let t1 = Float(self.player.currentTime().value)
let t2 = Float(self.player.currentTime().timescale)
let currentSeconds = t1 / t2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM