mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-25 12:40:36 +00:00

git-subtree-dir: submodules/TelegramUI git-subtree-mainline: 5c1613d1048026b9e00a6ce753775cef87eb53fa git-subtree-split: fa3ac0b61a27c8dd3296518a15891a6f9750cbf2
57 lines
1.6 KiB
Swift
57 lines
1.6 KiB
Swift
import Foundation
|
|
import SwiftSignalKit
|
|
import AudioToolbox
|
|
|
|
private func loadSystemSoundFromBundle(name: String) -> SystemSoundID? {
|
|
let path = "\(frameworkBundle.resourcePath!)/\(name)"
|
|
let url = URL(fileURLWithPath: path)
|
|
var sound: SystemSoundID = 0
|
|
if AudioServicesCreateSystemSoundID(url as CFURL, &sound) == noErr {
|
|
return sound
|
|
}
|
|
return nil
|
|
}
|
|
|
|
public final class ServiceSoundManager {
|
|
private let queue = Queue()
|
|
private var messageDeliverySound: SystemSoundID?
|
|
private var incomingMessageSound: SystemSoundID?
|
|
|
|
init() {
|
|
self.queue.async {
|
|
self.messageDeliverySound = loadSystemSoundFromBundle(name: "MessageSent.caf")
|
|
self.incomingMessageSound = loadSystemSoundFromBundle(name: "notification.caf")
|
|
}
|
|
}
|
|
|
|
public func playMessageDeliveredSound() {
|
|
self.queue.async {
|
|
if let messageDeliverySound = self.messageDeliverySound {
|
|
AudioServicesPlaySystemSound(messageDeliverySound)
|
|
}
|
|
}
|
|
}
|
|
|
|
public func playIncomingMessageSound() {
|
|
self.queue.async {
|
|
if let incomingMessageSound = self.incomingMessageSound {
|
|
AudioServicesPlaySystemSound(incomingMessageSound)
|
|
}
|
|
}
|
|
}
|
|
|
|
public func playVibrationSound() {
|
|
self.queue.async {
|
|
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
|
|
}
|
|
}
|
|
|
|
public func playLockSound() {
|
|
self.queue.async {
|
|
AudioServicesPlaySystemSound(1100)
|
|
}
|
|
}
|
|
}
|
|
|
|
public let serviceSoundManager = ServiceSoundManager()
|