adamcichy / SwiftySound

SwiftySound is a simple library that lets you play sounds with a single line of code.
MIT License
1.25k stars 99 forks source link

Not able to play sound when using play method's completion handler. #36

Closed ivanlares closed 6 years ago

ivanlares commented 6 years ago

It works when I use the class method.

Sound.play(file: "ding.wav")

But it doesn't work when I use the code below. I tested on multiple devices.

        guard let soundUrl = Bundle.main.url(forResource: "ding", withExtension: "wav") else {
            print("error with ding url")
            return
        }
        guard let mySound = Sound(url: soundUrl) else {
            print("error with my sound object")
            return
        }

       let didPlay = mySound.play() {
            completed in
            print("completed: \(completed)")
        }

        // prints true
        print("didPlay: \(didPlay)")
ivanlares commented 6 years ago

I took a look at the example code and I realized that we need to make a Sound property when using the completion handler.

Where as before I simply created an instance in a method.