From 9d5a59fc1f02feab05898400666bc9d34009f46e Mon Sep 17 00:00:00 2001 From: Rubesh Date: Wed, 3 Apr 2024 21:26:15 +0800 Subject: [PATCH] Add main music --- TowerForge/TowerForge/Commons/Sounds/AudioManager.swift | 2 ++ .../TowerForge/ViewControllers/MainMenuViewController.swift | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/TowerForge/TowerForge/Commons/Sounds/AudioManager.swift b/TowerForge/TowerForge/Commons/Sounds/AudioManager.swift index 6751438e..a78544e3 100644 --- a/TowerForge/TowerForge/Commons/Sounds/AudioManager.swift +++ b/TowerForge/TowerForge/Commons/Sounds/AudioManager.swift @@ -79,6 +79,7 @@ internal class AudioManager: NSObject, AVAudioPlayerDelegate { /// Plays background music func playMainMusic() { + stopBackground() if !isMainPlaying { mainAudioPlayer?.play() isMainPlaying = true @@ -102,6 +103,7 @@ internal class AudioManager: NSObject, AVAudioPlayerDelegate { /// Plays background music func playBackground() { + stopMainMusic() if !isBackgroundPlaying { backgroundAudioPlayer?.play() isBackgroundPlaying = true diff --git a/TowerForge/TowerForge/ViewControllers/MainMenuViewController.swift b/TowerForge/TowerForge/ViewControllers/MainMenuViewController.swift index 608a8ef2..c07897c6 100644 --- a/TowerForge/TowerForge/ViewControllers/MainMenuViewController.swift +++ b/TowerForge/TowerForge/ViewControllers/MainMenuViewController.swift @@ -11,6 +11,11 @@ import UIKit class MainMenuViewController: UIViewController { var selectedGameMode: Mode = .deathMatch + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + AudioManager.shared.playMainMusic() + } + @IBAction private func DeathMatch(_ sender: Any) { selectedGameMode = .deathMatch performSegue(withIdentifier: "segueToGame", sender: self)