46 lines
1.2 KiB
Swift
46 lines
1.2 KiB
Swift
//
|
|
// SoundManager.swift
|
|
// GoldWars
|
|
//
|
|
// Created by Tim Herbst on 10.05.20.
|
|
// Copyright © 2020 SP2. All rights reserved.
|
|
//
|
|
|
|
import SpriteKit
|
|
import AVFoundation
|
|
|
|
class SoundManager {
|
|
static var audioPlayer = AVAudioPlayer()
|
|
static var backgroundMainMenuAudio: URL?
|
|
static var isMusicPlaying: Bool = false
|
|
static var isMusicEnabled: Bool = true
|
|
|
|
static func startMenuMusic() {
|
|
SoundManager.isMusicPlaying = true
|
|
backgroundMainMenuAudio = Bundle.main.url(forResource: "intro-music", withExtension: "mp3")
|
|
do {
|
|
audioPlayer = try AVAudioPlayer(contentsOf: backgroundMainMenuAudio!)
|
|
} catch {
|
|
print("Datei nicht gefunden!")
|
|
}
|
|
audioPlayer.numberOfLoops = -1
|
|
audioPlayer.prepareToPlay()
|
|
if SoundManager.isMusicEnabled == true {
|
|
audioPlayer.play()
|
|
}
|
|
}
|
|
|
|
static func stopMenuMusic() {
|
|
audioPlayer.pause()
|
|
SoundManager.isMusicPlaying = false
|
|
}
|
|
|
|
static func setVolume(_ volume: Float) {
|
|
audioPlayer.volume = volume
|
|
}
|
|
|
|
static func getVolume() -> Float {
|
|
return audioPlayer.volume
|
|
}
|
|
}
|