解决铃声播放问题

This commit is contained in:
UUNEO 2024-12-16 18:40:20 +08:00 committed by Feng
parent 6c4577e5ea
commit ea776ed7d0
2 changed files with 23 additions and 6 deletions

View File

@ -26,6 +26,10 @@ class SoundsViewController: BaseViewController<SoundsViewModel> {
//
let importSoundActionRelay = PublishRelay<URL>()
// ID
var currentSoundID: SystemSoundID = 0
// ULRL
var playingAudio: CFURL?
override func makeUI() {
self.title = NSLocalizedString("notificationSound")
@ -82,11 +86,24 @@ class SoundsViewController: BaseViewController<SoundsViewModel> {
}).disposed(by: rx.disposeBag)
output.playAction.drive(onNext: { url in
var soundID: SystemSoundID = 0
AudioServicesCreateSystemSoundID(url, &soundID)
AudioServicesPlaySystemSoundWithCompletion(soundID) {
AudioServicesDisposeSystemSoundID(soundID)
}
///
AudioServicesDisposeSystemSoundID(self.currentSoundID)
///
if self.playingAudio == url{
self.playingAudio = nil
self.currentSoundID = 0
return
}
self.playingAudio = url
AudioServicesCreateSystemSoundID(url, &self.currentSoundID)
AudioServicesPlaySystemSoundWithCompletion(self.currentSoundID) {
///
if self.playingAudio == url {
AudioServicesDisposeSystemSoundID(self.currentSoundID)
self.playingAudio = nil
self.currentSoundID = 0
}
}
}).disposed(by: rx.disposeBag)
output.pickerFile.drive(onNext: { [unowned self] _ in

View File

@ -179,6 +179,6 @@ SPEC CHECKSUMS:
SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a
SwiftyStoreKit: 6b9c08810269f030586dac1fae8e75871a82e84a
PODFILE CHECKSUM: 5ff0ad6db7c674915eab257bcc3673bde7360e63
PODFILE CHECKSUM: e499f90151cf50309319d3c7295e7cb0541725ef
COCOAPODS: 1.16.2