Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b40a6f0b4 | |||
| f9465f54a0 | |||
| 8ce28db471 | |||
| a84f834f45 | |||
| e3e3af2b7a | |||
| 6987458f0a | |||
| c912d5f381 | |||
| c444ae4c9f | |||
| 6d3f3c6d6f | |||
| bb7f1d1d0a | |||
| 6c446f27e0 |
@@ -259,7 +259,12 @@ class ViewController: UIViewController {
|
||||
@IBAction func rateChanged(_ sender: Any) {
|
||||
let speed = rateSlider.value
|
||||
rateLabel.text = "rate: \(speed)x"
|
||||
SAPlayer.shared.rate = speed
|
||||
|
||||
if skipSilencesSwitch.isOn {
|
||||
SAPlayer.Features.SkipSilences.setRateSafely(speed) // if using Skip Silences, we need use this version of setting rate to safely change the rate with the feature enabled.
|
||||
} else {
|
||||
SAPlayer.shared.rate = speed
|
||||
}
|
||||
}
|
||||
@IBAction func reverbChanged(_ sender: Any) {
|
||||
let reverb = reverbSlider.value
|
||||
|
||||
@@ -117,16 +117,9 @@ For more details and specifics look at the [API documentation](#api-in-detail) b
|
||||
|
||||
## Contact
|
||||
|
||||
### Issues
|
||||
### Issues or questions
|
||||
|
||||
Submit any issues or requests [on the Github repo](https://github.com/tanhakabir/SwiftAudioPlayer/issues).
|
||||
|
||||
### Any questions?
|
||||
|
||||
Feel free to reach out to either of us:
|
||||
|
||||
[tanhakabir](https://github.com/tanhakabir), tanhakabir.ca@gmail.com
|
||||
[JonMercer](https://github.com/JonMercer), mercer.jon@gmail.com
|
||||
Submit any issues, requests, and questions [on the Github repo](https://github.com/tanhakabir/SwiftAudioPlayer/issues).
|
||||
|
||||
### License
|
||||
|
||||
|
||||
+35
-9
@@ -123,13 +123,6 @@ public class SAPlayer {
|
||||
|
||||
node.rate = value
|
||||
playbackRateOfAudioChanged(rate: value)
|
||||
|
||||
// if skip silences was on, reset it to have the new rate
|
||||
// TODO fix this to rate being broadcasted and handled in only Features.SkipSilences https://github.com/tanhakabir/SwiftAudioPlayer/issues/77
|
||||
// if Features.SkipSilences.enabled && !(value == rate ?? 1.0 - 0.5 || value == rate ?? 1.0 + 0.5) {
|
||||
// _ = Features.SkipSilences.disable()
|
||||
// _ = Features.SkipSilences.enable()
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,6 +244,7 @@ public class SAPlayer {
|
||||
}
|
||||
|
||||
audioModifiers.append(AVAudioUnitTimePitch(audioComponentDescription: componentDescription))
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption), name: AVAudioSession.interruptionNotification, object: nil)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,6 +284,36 @@ public class SAPlayer {
|
||||
func addUrlToMapping(url: URL) {
|
||||
presenter.addUrlToKeyMap(url)
|
||||
}
|
||||
|
||||
@objc func handleInterruption(notification: Notification) {
|
||||
guard let userInfo = notification.userInfo,
|
||||
let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
|
||||
let type = AVAudioSession.InterruptionType(rawValue: typeValue) else {
|
||||
return
|
||||
}
|
||||
|
||||
// Switch over the interruption type.
|
||||
switch type {
|
||||
|
||||
case .began:
|
||||
// An interruption began. Update the UI as necessary.
|
||||
pause()
|
||||
|
||||
case .ended:
|
||||
// An interruption ended. Resume playback, if appropriate.
|
||||
|
||||
guard let optionsValue = userInfo[AVAudioSessionInterruptionOptionKey] as? UInt else { return }
|
||||
let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
|
||||
if options.contains(.shouldResume) {
|
||||
// An interruption ended. Resume playback.
|
||||
play()
|
||||
} else {
|
||||
// An interruption ended. Don't resume playback.
|
||||
}
|
||||
|
||||
default: ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum SAPlayerBitrate {
|
||||
@@ -416,8 +440,9 @@ extension SAPlayer {
|
||||
// This prevents a crash where an owning engine already exists.
|
||||
presenter.handleClear()
|
||||
|
||||
presenter.handlePlaySavedAudio(withSavedUrl: url)
|
||||
// order here matters, need to set media info before trying to play audio
|
||||
self.mediaInfo = mediaInfo
|
||||
presenter.handlePlaySavedAudio(withSavedUrl: url)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -455,8 +480,9 @@ extension SAPlayer {
|
||||
// This prevents a crash where an owning engine already exists.
|
||||
presenter.handleClear()
|
||||
|
||||
presenter.handlePlayStreamedAudio(withRemoteUrl: url, bitrate: bitrate)
|
||||
// order here matters, need to set media info before trying to play audio
|
||||
self.mediaInfo = mediaInfo
|
||||
presenter.handlePlayStreamedAudio(withRemoteUrl: url, bitrate: bitrate)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,8 @@ extension SAPlayer {
|
||||
/**
|
||||
Enable feature to skip silences in spoken word audio. The player will speed up the rate of audio playback when silence is detected. This can be called at any point of audio playback.
|
||||
|
||||
- Important: The first audio modifier must be the default `AVAudioUnitTimePitch` that comes with the SAPlayer for this feature to work.
|
||||
- Precondition: The first audio modifier must be the default `AVAudioUnitTimePitch` that comes with the SAPlayer for this feature to work.
|
||||
- Important: If you want to change the rate of the overall player while having skip silences on, please use `SAPlayer.Features.SkipSilences.setRateSafely()` to properly set the rate of the player. Any rate changes to the player will be ignored while using Skip Silences otherwise.
|
||||
*/
|
||||
public static func enable() -> Bool {
|
||||
guard let engine = SAPlayer.shared.engine else { return false }
|
||||
@@ -72,7 +73,7 @@ extension SAPlayer {
|
||||
/**
|
||||
Disable feature to skip silences in spoken word audio. The player will speed up the rate of audio playback when silence is detected. This can be called at any point of audio playback.
|
||||
|
||||
- Important: The first audio modifier must be the default `AVAudioUnitTimePitch` that comes with the SAPlayer for this feature to work.
|
||||
- Precondition: The first audio modifier must be the default `AVAudioUnitTimePitch` that comes with the SAPlayer for this feature to work.
|
||||
*/
|
||||
public static func disable() -> Bool {
|
||||
guard let engine = SAPlayer.shared.engine else { return false }
|
||||
@@ -83,6 +84,16 @@ extension SAPlayer {
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
Use this function to set the overall rate of the player for when skip silences is on. This ensures that the overall rate will be what is set through this function even as skip silences is on; if this function is not used then any changes asked of from the overall player while skip silences is on won't be recorded!
|
||||
|
||||
- Important: The first audio modifier must be the default `AVAudioUnitTimePitch` that comes with the SAPlayer for this feature to work.
|
||||
*/
|
||||
public static func setRateSafely(_ rate: Float) {
|
||||
originalRate = rate
|
||||
SAPlayer.shared.rate = rate
|
||||
}
|
||||
|
||||
private static func scaledPower(power: Float) -> Float {
|
||||
guard power.isFinite else { return 0.0 }
|
||||
let minDb: Float = -80.0
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'SwiftAudioPlayer'
|
||||
s.version = '5.0.4'
|
||||
s.version = '5.2.0'
|
||||
s.summary = 'SwiftAudioPlayer is a Swift based audio player that can handle streaming from a remote location and audio manipulation.'
|
||||
|
||||
# This description is used to generate tags and improve search results.
|
||||
|
||||
Reference in New Issue
Block a user