R – Showing duration of a song in uilabel or uitextfield

avaudioplayeriphone

I am developing a music player application. I have picked music files from the ipod library, and is playing them. I'm using AVAudioPlayer for this. What i need now is to show the duration of the song on the top of the view. I got the duration as

NSTimeInterval *duration = [musicplayer duration];

But i dont know how to use it to display on the view, on uilabel or uitextfield. Or even using any other value.
Pls help..

Best Answer

Assuming label is your UILabel, try this:

label.text = [NSString stringWithFormat:@"%lf", duration];

Or, if you want it in minute:seconds

label.text = [NSString stringWithFormat:@"%d:%d", (int) (x / 60), ((int) x % 60)]

String formatting is your friend here.

Related Topic