mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
解决铃声播放问题
This commit is contained in:
parent
6c4577e5ea
commit
ea776ed7d0
@ -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
|
||||
|
||||
@ -179,6 +179,6 @@ SPEC CHECKSUMS:
|
||||
SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a
|
||||
SwiftyStoreKit: 6b9c08810269f030586dac1fae8e75871a82e84a
|
||||
|
||||
PODFILE CHECKSUM: 5ff0ad6db7c674915eab257bcc3673bde7360e63
|
||||
PODFILE CHECKSUM: e499f90151cf50309319d3c7295e7cb0541725ef
|
||||
|
||||
COCOAPODS: 1.16.2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user