Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. //
  2. // MNGSoundManager.swift
  3. //
  4. //
  5. // Created by Tommie N. Carter, Jr., MBA on 10/26/15.
  6. // Copyright © 2015 MING Technology. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10. import AudioToolbox
  11.  
  12. class MNGSoundManager {
  13. static let sharedInstance = MNGSoundManager()
  14.  
  15. //urls for sound clips
  16. let backSoundURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("264447__kickhat__open-button-2", ofType: "wav")!)
  17. let buttonSoundURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("80921__justinbw__buttonchime02up", ofType: "wav")!)
  18. let deleteSoundURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("67454__splashdust__negativebeep", ofType: "wav")!)
  19. let dropSoundURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("191678__porphyr__waterdrop", ofType: "wav")!)
  20. let mainSwitchOpenSoundURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("195912__acpascal__start-beep", ofType: "wav")!)
  21. let mainSwitchCloseSoundURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("191754__fins__button-5", ofType: "wav")!)
  22. let popupSoundURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("242502__gabrielaraujo__pop-up-notification", ofType: "wav")!)
  23. let optionSoundURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("126418__cabeeno-rossley__button-select", ofType: "wav")!)
  24.  
  25.  
  26. private var _backSnd:SystemSoundID? = nil
  27. lazy var backSound: SystemSoundID = {
  28. if self._backSnd != nil { return self._backSnd! }
  29.  
  30. var sndID : SystemSoundID = 0
  31. let url = self.backSoundURL
  32. AudioServicesCreateSystemSoundID (
  33. url,
  34. &sndID)
  35.  
  36. self._backSnd = sndID
  37. return sndID
  38. }()
  39. private var _btnSnd:SystemSoundID? = nil
  40. lazy var buttonSound: SystemSoundID = {
  41. if self._btnSnd != nil { return self._btnSnd! }
  42.  
  43. var sndID : SystemSoundID = 0
  44. let url = self.buttonSoundURL
  45. AudioServicesCreateSystemSoundID (
  46. url,
  47. &sndID)
  48.  
  49. self._btnSnd = sndID
  50. return sndID
  51. }()
  52. private var _deleteSnd:SystemSoundID? = nil
  53. lazy var deleteSound: SystemSoundID = {
  54. if self._deleteSnd != nil { return self._deleteSnd! }
  55.  
  56. var sndID : SystemSoundID = 0
  57. let url = self.deleteSoundURL
  58. AudioServicesCreateSystemSoundID (
  59. url,
  60. &sndID)
  61.  
  62. self._deleteSnd = sndID
  63. return sndID
  64. }()
  65. private var _dropSnd:SystemSoundID? = nil
  66. lazy var dropSound: SystemSoundID = {
  67. if self._dropSnd != nil { return self._dropSnd! }
  68.  
  69. var sndID : SystemSoundID = 0
  70. let url = self.dropSoundURL
  71. AudioServicesCreateSystemSoundID (
  72. url,
  73. &sndID)
  74.  
  75. self._dropSnd = sndID
  76. return sndID
  77. }()
  78. private var _mainSndClose:SystemSoundID? = nil
  79. lazy var mainSwitchCloseSound: SystemSoundID = {
  80. if self._mainSndClose != nil { return self._mainSndClose! }
  81.  
  82. var sndID : SystemSoundID = 0
  83. let url = self.mainSwitchCloseSoundURL
  84. AudioServicesCreateSystemSoundID (
  85. url,
  86. &sndID)
  87.  
  88. self._mainSndClose = sndID
  89. return sndID
  90. }()
  91. private var _mainSndOpen:SystemSoundID? = nil
  92. lazy var mainSwitchOpenSound: SystemSoundID = {
  93. if self._mainSndOpen != nil { return self._mainSndOpen! }
  94.  
  95. var sndID : SystemSoundID = 0
  96. let url = self.mainSwitchOpenSoundURL
  97. AudioServicesCreateSystemSoundID (
  98. url,
  99. &sndID)
  100.  
  101. self._mainSndOpen = sndID
  102. return sndID
  103. }()
  104. private var _popupSnd:SystemSoundID? = nil
  105. lazy var popupSound: SystemSoundID = {
  106. if self._popupSnd != nil { return self._popupSnd! }
  107.  
  108. var sndID : SystemSoundID = 0
  109. let url = self.popupSoundURL
  110. AudioServicesCreateSystemSoundID (
  111. url,
  112. &sndID)
  113.  
  114. self._popupSnd = sndID
  115. return sndID
  116. }()
  117. private var _optionSnd:SystemSoundID? = nil
  118. lazy var optionSound: SystemSoundID = {
  119. if self._optionSnd != nil { return self._optionSnd! }
  120.  
  121. var sndID : SystemSoundID = 0
  122. let url = self.optionSoundURL
  123. AudioServicesCreateSystemSoundID (
  124. url,
  125. &sndID)
  126.  
  127. self._optionSnd = sndID
  128. return sndID
  129. }()
  130.  
  131. deinit
  132. {
  133. AudioServicesDisposeSystemSoundID(self.buttonSound)
  134. AudioServicesDisposeSystemSoundID(self.mainSwitchOpenSound)
  135. AudioServicesDisposeSystemSoundID(self.mainSwitchCloseSound)
  136. AudioServicesDisposeSystemSoundID(self.deleteSound)
  137. AudioServicesDisposeSystemSoundID(self.dropSound)
  138. AudioServicesDisposeSystemSoundID(self.optionSound)
  139. AudioServicesDisposeSystemSoundID(self.popupSound)
  140.  
  141. _backSnd = nil
  142. _deleteSnd = nil
  143. _dropSnd = nil
  144. _mainSndClose = nil
  145. _mainSndOpen = nil
  146. _optionSnd = nil
  147. _popupSnd = nil
  148.  
  149. }
  150. func playBackSound(){
  151. AudioServicesPlaySystemSound(self.backSound)
  152. }
  153. func playButtonSound(){
  154. AudioServicesPlaySystemSound(self.buttonSound)
  155. }
  156. func playDeleteSound(){
  157. AudioServicesPlaySystemSound(self.deleteSound)
  158. }
  159. func playDropSound(){
  160. AudioServicesPlaySystemSound(self.dropSound)
  161. }
  162. func playMainSwitchOpenSound(){
  163. AudioServicesPlaySystemSound(self.mainSwitchOpenSound)
  164. }
  165. func playMainSwitchCloseSound(){
  166. AudioServicesPlaySystemSound(self.mainSwitchCloseSound)
  167. }
  168. func playPopupSound(){
  169. AudioServicesPlaySystemSound(self.popupSound)
  170. }
  171. func playOptionSound(){
  172. AudioServicesPlaySystemSound(self.optionSound)
  173. }
  174. func vibrateDevice() {
  175. AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
  176. }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement