2015-04-03 102 views
5

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

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()) 
+0

檢查您的視頻是否正在播放......你最好發佈更多的代碼 – 2015-04-03 13:31:39

+0

@AlexChan我怎麼能確定視頻是否是打還是不 – 2015-04-06 06:32:04

+0

我不知道這是確定:'讓物品1 = AVPlayerItem .init(URL:NSURL(string:path))'。但試試這個:'let item1 = AVPlayerItem(URL:xxx)' – 2015-04-07 01:57:36

回答

10

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

let t1 = Float(self.player.currentTime().value) 
let t2 = Float(self.player.currentTime().timescale) 
let currentSeconds = t1/t2 
相關問題