update callcenter
This commit is contained in:
122
Pods/DDAudioPlayerKit_Private/DDAudioPlayerKit_Private/Classes/DDAudioService.swift
generated
Normal file
122
Pods/DDAudioPlayerKit_Private/DDAudioPlayerKit_Private/Classes/DDAudioService.swift
generated
Normal file
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// SystemSoundPlayer.swift
|
||||
// DDAudioPlayerKit_Private
|
||||
//
|
||||
// Created by 中道 on 2023/8/31.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import AVFoundation
|
||||
|
||||
public let DDAS = DDAudioService.default
|
||||
|
||||
open class DDAudioService {
|
||||
public static let `default` = DDAudioService()
|
||||
|
||||
private var audioSoundID : SystemSoundID = 0
|
||||
private var vibrateSoundID : SystemSoundID = 0
|
||||
private var audioNumberOfLoops : Int = 0
|
||||
private var vibrateNumberOfLoops : Int = 0
|
||||
private var endSound : Bool = false
|
||||
private var endVibrate : Bool = false
|
||||
|
||||
public func playSoundWithVibrate(audioUrl:URL,numberOfLoops:Int = 1) {
|
||||
playVibrate(numberOfLoops: -1)
|
||||
playSound(audioUrl: audioUrl,numberOfLoops: numberOfLoops) {[weak self] in
|
||||
self?.stopSound()
|
||||
self?.stopVibrate()
|
||||
}
|
||||
}
|
||||
|
||||
public func stopSoundWithVibrate() {
|
||||
stopSound()
|
||||
stopVibrate()
|
||||
}
|
||||
|
||||
public func playSound(audioUrl:URL,numberOfLoops:Int = 1, endCompletionBlock: (() -> Void)? = nil) {
|
||||
self.audioNumberOfLoops = numberOfLoops
|
||||
|
||||
var audioSoundID:SystemSoundID = 0
|
||||
AudioServicesCreateSystemSoundID(audioUrl as CFURL, &audioSoundID)
|
||||
self.audioSoundID = audioSoundID
|
||||
DispatchQueue.global().async {[weak self] in
|
||||
self?.playSound(audioSoundID: audioSoundID,leftNumberOfLoops: numberOfLoops,endCompletionBlock: {
|
||||
if endCompletionBlock != nil {
|
||||
endCompletionBlock!()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public func playVibrate(numberOfLoops:Int = 1, endCompletionBlock: (() -> Void)? = nil) {
|
||||
self.audioNumberOfLoops = numberOfLoops
|
||||
|
||||
var vibrateSoundID : SystemSoundID = 0
|
||||
vibrateSoundID = kSystemSoundID_Vibrate
|
||||
self.vibrateSoundID = vibrateSoundID
|
||||
DispatchQueue.global().async {[weak self] in
|
||||
self?.playVibrate(vibrateSoundID: vibrateSoundID, leftNumberOfLoops: numberOfLoops,endCompletionBlock: {
|
||||
if endCompletionBlock != nil {
|
||||
endCompletionBlock!()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public func stopSound() {
|
||||
endSound = true
|
||||
AudioServicesDisposeSystemSoundID(audioSoundID)
|
||||
}
|
||||
|
||||
public func stopVibrate() {
|
||||
endVibrate = true
|
||||
AudioServicesDisposeSystemSoundID(vibrateSoundID)
|
||||
}
|
||||
|
||||
private func playSound(audioSoundID:SystemSoundID,leftNumberOfLoops:Int,timeInterval:TimeInterval = 0,eachLoopCompletionBlock: (() -> Void)? = nil, endCompletionBlock: (() -> Void)? = nil) {
|
||||
var changeLeftNumberOfLoops = leftNumberOfLoops
|
||||
AudioServicesPlaySystemSoundWithCompletion(audioSoundID) {[weak self] in
|
||||
if eachLoopCompletionBlock != nil {
|
||||
eachLoopCompletionBlock!()
|
||||
}
|
||||
|
||||
// 当前的剩余为0就结束
|
||||
changeLeftNumberOfLoops-=1
|
||||
if changeLeftNumberOfLoops == 0 || self?.endSound == true {
|
||||
self?.stopSound()
|
||||
if endCompletionBlock != nil {
|
||||
endCompletionBlock!()
|
||||
}
|
||||
print("sound播放结束")
|
||||
}else{
|
||||
DispatchQueue.global().asyncAfter(deadline: .now() + timeInterval, execute: {
|
||||
self?.playSound(audioSoundID: audioSoundID, leftNumberOfLoops: changeLeftNumberOfLoops,timeInterval: timeInterval)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func playVibrate(vibrateSoundID:SystemSoundID,leftNumberOfLoops:Int,timeInterval:TimeInterval = 0,eachLoopCompletionBlock: (() -> Void)? = nil, endCompletionBlock: (() -> Void)? = nil) {
|
||||
var changeLeftNumberOfLoops = leftNumberOfLoops
|
||||
AudioServicesPlayAlertSoundWithCompletion(vibrateSoundID) {[weak self] in
|
||||
if eachLoopCompletionBlock != nil {
|
||||
eachLoopCompletionBlock!()
|
||||
}
|
||||
|
||||
// 当前的剩余为0就结束
|
||||
changeLeftNumberOfLoops-=1
|
||||
if changeLeftNumberOfLoops == 0 || self?.endVibrate == true {
|
||||
self?.stopVibrate()
|
||||
if endCompletionBlock != nil {
|
||||
endCompletionBlock!()
|
||||
}
|
||||
print("vibrate播放结束")
|
||||
}else{
|
||||
DispatchQueue.global().asyncAfter(deadline: .now() + timeInterval, execute: {
|
||||
self?.playVibrate(vibrateSoundID: vibrateSoundID, leftNumberOfLoops: changeLeftNumberOfLoops,timeInterval: timeInterval)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
19
Pods/DDAudioPlayerKit_Private/LICENSE
generated
Normal file
19
Pods/DDAudioPlayerKit_Private/LICENSE
generated
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2023 DDIsFriend <DDIsFriend@163.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
29
Pods/DDAudioPlayerKit_Private/README.md
generated
Normal file
29
Pods/DDAudioPlayerKit_Private/README.md
generated
Normal file
@@ -0,0 +1,29 @@
|
||||
# DDAudioPlayerKit_Private
|
||||
|
||||
[](https://travis-ci.org/DDIsFriend/DDAudioPlayerKit_Private)
|
||||
[](https://cocoapods.org/pods/DDAudioPlayerKit_Private)
|
||||
[](https://cocoapods.org/pods/DDAudioPlayerKit_Private)
|
||||
[](https://cocoapods.org/pods/DDAudioPlayerKit_Private)
|
||||
|
||||
## Example
|
||||
|
||||
To run the example project, clone the repo, and run `pod install` from the Example directory first.
|
||||
|
||||
## Requirements
|
||||
|
||||
## Installation
|
||||
|
||||
DDAudioPlayerKit_Private is available through [CocoaPods](https://cocoapods.org). To install
|
||||
it, simply add the following line to your Podfile:
|
||||
|
||||
```ruby
|
||||
pod 'DDAudioPlayerKit_Private'
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
DDIsFriend, DDIsFriend@163.com
|
||||
|
||||
## License
|
||||
|
||||
DDAudioPlayerKit_Private is available under the MIT license. See the LICENSE file for more info.
|
||||
Reference in New Issue
Block a user