0

I have the following code to attempt to show the time elapsed of my audio file:

 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 } 

The timer is set in this code in view did load:

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

There are numbers displayed in the lable but they are completely random, so no display of seconds and minutes. What am I doing wrong here? Is it the way I am getting the current Time?

3
  • 1
    %d it is for integers. Looks like you are working with Double/NSTimeInterval or Float Commented Apr 5, 2016 at 1:57
  • stackoverflow.com/a/30772571/2303865 Commented Apr 5, 2016 at 2:00
  • the numbers I am getting are like this: 15980621, 39, 32657959, 34, 49332843, 18, 65981395, 17, 82654148, 33, 99314348, 47, 115990088, 56, 132647323, 8, 149315021, 16, Commented Apr 5, 2016 at 2:24

1 Answer 1

0

I changed this line to:

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

I have no idea why this works, but it does the trick!

Sign up to request clarification or add additional context in comments.

1 Comment

"I have no idea why this works, but it works!" the meme about programmer life

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.