Login required for access
In order to watch this lesson, you'll need to login to the website.
Tracking Playback Time
Podcasts
One of the final features of an audio application is to track the current play time of your audio stream. In today's lesson, we'll use a Periodic Observer to monitor the play time of our AVPlayer object. Because the object's that we get back are CMTime types, we'll need to convert them into pretty display strings with special formats. Once we finish the implementation on this, we'll move onto modifying the duration label as well as the scrubber slider to update as the podcast episode is playing. Enjoy.
```swift extension CMTime { func toDisplayString() -> String { if CMTimeGetSeconds(self).isNaN { return "--:--" } let totalSeconds = Int(CMTimeGetSeconds(self)) let seconds = totalSeconds % 60 let minutes = totalSeconds % (60 * 60) / 60 let hours = totalSeconds / 60 / 60 let timeFormatString = String(format: "%02d:%02d:%02d", hours, minutes, seconds) return timeFormatString } } ```

Comments (8)
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
HELP & SUPPORT