Can I somehow turn off all the music in the scene at once?

import Foundation import SpriteKit import AVFoundation class Start: SKScene, SKPhysicsContactDelegate { var isPlaying = false var audioN: AVAudioPlayer! //Кнопка func buttonTap(sender:UIButton){ if (sender.tag == 1){ if isPlaying { isPlaying = false if (isPlaying == false){ } dispatch_async(dispatch_get_main_queue(), { }) } else { isPlaying = true if (isPlaying == true){ audioN = try? AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PlayM", ofType: "mp3")!)) } dispatch_async(dispatch_get_main_queue(), { }) } } //И дальше мне эти звуки еще использовать нужно будет func PlayGame(){ audioN.play() } 
  • one
    what class plays music? - Max Mikheyenko
  • class SKScene var audioN= try? AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PlayM", ofType: "mp3")!)) var audioN= try? AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PlayM", ofType: "mp3")!)) - Leci
  • one
    I think audioN.stop can help - Max Mikheyenko
  • one
    Little is not the case, the fact that I turn on the music from the button to lose, I write like this: audioN= try? AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PlayM", ofType: "mp3")!)) audioN= try? AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PlayM", ofType: "mp3")!)) So stop here will not work - Leci
  • one
    add ka you all the code that you now have in question, until you closed it - Max Mikheyenko

1 answer 1

To stop the music that is already playing delvite just audioN.stop()

To prevent the launch of music, as I have already written, you need to make a variable that will store whether the sound is now turned on and based on this, launch new sounds.

 if(self.soundEnabled) { audioN.play() }