2016-04-05 31 views
0

我有下面的代码,以试图表明我的音频文件的时间流逝:时间AVPlayer过去时显示陌生号码迅速

func updateTime() { 
    let currentTime = Int(player!.currentTime().value) 
    let minutes = currentTime/60 
    print(minutes) 
    let seconds = currentTime - minutes * 60 
    print(seconds) 
    time.text = NSString(format: "%02d:%02d", minutes,seconds) as String 
} 

计时器在此代码视图设置做负载:

play.play() 

    timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(.updateTime), userInfo: nil, repeats: true) 

有数字显示在标签,但他们是完全随机的,所以不显示秒和分钟。我在这里做错了什么?这是我获得当前时间的方式吗?

+1

%d它是整数。看起来你用双人/ NSTimeInterval工作或浮动 –

+0

http://stackoverflow.com/a/30772571/2303865 –

+0

我得到的数字是这样的: 15980621, 39, 32657959, 34, 49332843, 18, 65981395, 17, 82654148, 33, 99314348, 47, 115990088, 56, 132647323, 8, 149315021, 16 – kangarooChris

回答

0

我改变了这一行:

let currentTime = Int(player!.currentTime().value)/Int(player!.currentTime().timescale) 

我不知道为什么这个作品,但它的伎俩!