mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
Swift
38 lines
1.1 KiB
Swift
import AudioToolbox
|
|
import AVFoundation
|
|
|
|
public final class CallRingTonePlayer {
|
|
|
|
public static let shared = CallRingTonePlayer()
|
|
|
|
private var vibrationTimer: Timer?
|
|
private var player: AVAudioPlayer?
|
|
|
|
public func startVibration() {
|
|
vibrationTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { _ in
|
|
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
|
|
}
|
|
}
|
|
|
|
public func stopVibrationIfPossible() {
|
|
vibrationTimer?.invalidate()
|
|
vibrationTimer = nil
|
|
}
|
|
|
|
public func startPlayingRingTone() {
|
|
guard let url = Bundle.main.url(forResource: "ringing", withExtension: "mp3") else { return }
|
|
do {
|
|
player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue)
|
|
player?.numberOfLoops = -1
|
|
player?.play()
|
|
} catch let error {
|
|
print(error.localizedDescription)
|
|
}
|
|
}
|
|
|
|
public func stopPlayingRingTone() {
|
|
guard let player = player else { return }
|
|
player.stop()
|
|
}
|
|
}
|