خرید بک لینک

Vote count: 0

I am making a simple game that involves users pressing unbuttons. Each time the user presses a button I want a sound to play. The sound file that I want to play is 3 seconds long. However it is highly likely that the user will press 1 or more uibuttons onscreen within the 3 second window that the sound is playing. So at the moment if a second UIButton is press while the sound is playing than the sound will not play. How can I have it so that the buttons play the sound even if the the original sound is playing?

import UIKit
import AVFoundation

class ViewController: UIViewController {

var player:AVAudioPlayer = AVAudioPlayer()

override func viewDidLoad() {
    super.viewDidLoad()

    let audioPath = NSBundle.mainBundle().pathForResource("soundbing", ofType: "mp3")
    var error:NSError? = nil
    do {
        player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
    }
    catch {
        print("Something bad happened")
    }

    }

@IBAction func play(sender: UIButton) {
    player.play()

}

@IBAction func play(sender: UIButton) {
    player.play()

}

@IBAction func play(sender: UIButton) {
    player.play()

}

asked 56 secs ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 5 تير 1395 ساعت: 16:19

صفحه بندی