UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How to use the play(atTime: 1) function.

Forums > SwiftUI

I am doing some coding on my Ipad using a blank page on Swift Playgrounds.

I am trying to learn how to use the play(atTime: TimeInterval) function

I thought the code below would play the sound twice. If I run this code the sound plays once. The second one doesn't play. The time interval works even if it is zero. If I run the first instance only it plays once poorly.

What is the correct way to use this function to play sounds at different times? I can put the complete code in if anyone is interested.

t = self.ClickPlayer!.deviceCurrentTime

 self.ClickPlayer?.currentTime = 0
 self.ClickPlayer?.volume = 5
 self.ClickPlayer?.play(atTime: t+1)

 self.ClickPlayer?.currentTime = 0
 self.ClickPlayer?.volume = 5
 self.ClickPlayer?.play(atTime: t + 5)

The Apple documentation states the play(atTime: TimeInterval) function "Plays a sound asynchronously, starting at a specified point in the audio output device’s timeline" and should be ideal for creating loops. Thanks if you have a look at this.

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.