Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| af3d553011 | |||
| d0f9127c65 | |||
| 27d5ce4f03 | |||
| 3f93bd1a86 | |||
| 20c0253f68 | |||
| 5e78c446a9 | |||
| 487b071490 | |||
| b79d16b409 | |||
| 4684a92380 | |||
| 2cff597e45 |
+4
-4
@@ -48,7 +48,7 @@
|
||||
A470FE2125F9AF1400F135FF /* AudioQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = A470FE2025F9AF1400F135FF /* AudioQueue.swift */; };
|
||||
A4827771262A216C00B6918A /* StreamingDownloadDirector.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4827770262A216C00B6918A /* StreamingDownloadDirector.swift */; };
|
||||
A4B4CC122223ED2A0045554B /* SAPlayerDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4B4CC112223ED2A0045554B /* SAPlayerDownloader.swift */; };
|
||||
A4FBA6B5221B74C900D5A353 /* SALockScreenInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4FBA6B3221B74C900D5A353 /* SALockScreenInfo.swift */; };
|
||||
A4FBA6B5221B74C900D5A353 /* SAPlayerHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4FBA6B3221B74C900D5A353 /* SAPlayerHelpers.swift */; };
|
||||
A4FBA6B7221BAC3D00D5A353 /* SAPlayerUpdateSubscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4FBA6B6221BAC3D00D5A353 /* SAPlayerUpdateSubscription.swift */; };
|
||||
A4FBA6B9221BAF8700D5A353 /* SAAudioAvailabilityRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4FBA6B8221BAF8700D5A353 /* SAAudioAvailabilityRange.swift */; };
|
||||
E08AD6157EF688FE832F866CBCDA3532 /* SwiftAudioPlayer-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = FB83B3B4253D41C37C5563D34D450BF8 /* SwiftAudioPlayer-dummy.m */; };
|
||||
@@ -134,7 +134,7 @@
|
||||
A470FE2025F9AF1400F135FF /* AudioQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioQueue.swift; sourceTree = "<group>"; };
|
||||
A4827770262A216C00B6918A /* StreamingDownloadDirector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamingDownloadDirector.swift; sourceTree = "<group>"; };
|
||||
A4B4CC112223ED2A0045554B /* SAPlayerDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SAPlayerDownloader.swift; sourceTree = "<group>"; };
|
||||
A4FBA6B3221B74C900D5A353 /* SALockScreenInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SALockScreenInfo.swift; sourceTree = "<group>"; };
|
||||
A4FBA6B3221B74C900D5A353 /* SAPlayerHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SAPlayerHelpers.swift; sourceTree = "<group>"; };
|
||||
A4FBA6B6221BAC3D00D5A353 /* SAPlayerUpdateSubscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SAPlayerUpdateSubscription.swift; sourceTree = "<group>"; };
|
||||
A4FBA6B8221BAF8700D5A353 /* SAAudioAvailabilityRange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SAAudioAvailabilityRange.swift; sourceTree = "<group>"; };
|
||||
AB41D88A2C694FBDF26EA56381EED25F /* Pods-SwiftAudioPlayer_Example-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-SwiftAudioPlayer_Example-dummy.m"; sourceTree = "<group>"; };
|
||||
@@ -342,7 +342,7 @@
|
||||
A4681FE2220117B50018AB51 /* Source */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A4FBA6B3221B74C900D5A353 /* SALockScreenInfo.swift */,
|
||||
A4FBA6B3221B74C900D5A353 /* SAPlayerHelpers.swift */,
|
||||
A4681F8D2200E00E0018AB51 /* SAPlayer.swift */,
|
||||
A411CE4525F9609D0039E1CD /* SAPlayerFeatures.swift */,
|
||||
A4FBA6B6221BAC3D00D5A353 /* SAPlayerUpdateSubscription.swift */,
|
||||
@@ -526,7 +526,7 @@
|
||||
A4681FCF220113A40018AB51 /* AudioConverterListener.swift in Sources */,
|
||||
A4681FE1220113E70018AB51 /* Constants.swift in Sources */,
|
||||
A40DBE292391D9CA00F86146 /* Data.swift in Sources */,
|
||||
A4FBA6B5221B74C900D5A353 /* SALockScreenInfo.swift in Sources */,
|
||||
A4FBA6B5221B74C900D5A353 /* SAPlayerHelpers.swift in Sources */,
|
||||
A4681FC6220113880018AB51 /* SAPlayer.swift in Sources */,
|
||||
A4FBA6B7221BAC3D00D5A353 /* SAPlayerUpdateSubscription.swift in Sources */,
|
||||
A4681FC72201138B0018AB51 /* SAPlayerDelegate.swift in Sources */,
|
||||
|
||||
@@ -239,5 +239,6 @@ class AudioEngine: AudioEngineProtocol {
|
||||
if let audioModifiers = audioModifiers, audioModifiers.count > 0 {
|
||||
audioModifiers.forEach { engine.detach($0) }
|
||||
}
|
||||
Log.info("invalidated engine for key \(key)")
|
||||
}
|
||||
}
|
||||
|
||||
+22
-9
@@ -180,15 +180,9 @@ public class SAPlayer {
|
||||
public var audioModifiers: [AVAudioUnit] = []
|
||||
|
||||
/**
|
||||
List of audio URLs queued for playback.
|
||||
List of queued audio for playback. You can edit this list as you wish to modify the queue.
|
||||
*/
|
||||
public var audioQueued: [URL] {
|
||||
get {
|
||||
return presenter.audioQueue.map { (queued) -> URL in
|
||||
return queued.url
|
||||
}
|
||||
}
|
||||
}
|
||||
public var audioQueued: [SAAudioQueueItem] = []
|
||||
|
||||
/**
|
||||
Total duration of current audio initialized. Returns nil if no audio is initialized in player.
|
||||
@@ -513,7 +507,7 @@ extension SAPlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
Queues saved audio to be played next. The URLs in the queuecan be both remote or on disk but once the queued audio starts playing it will start buffering and loading then. This means no guarantee for a 'gapless' playback where there might be several moments in between one audio ending and another starting due to buffering remote audio.
|
||||
Queues saved audio to be played next. The URLs in the queue can be both remote or on disk but once the queued audio starts playing it will start buffering and loading then. This means no guarantee for a 'gapless' playback where there might be several moments in between one audio ending and another starting due to buffering remote audio.
|
||||
|
||||
- Parameter withSavedUrl: The URL of the audio saved on the device.
|
||||
- Parameter mediaInfo: The media information of the audio to show on the lockscreen media player (optional).
|
||||
@@ -522,6 +516,25 @@ extension SAPlayer {
|
||||
presenter.handleQueueSavedAudio(withSavedUrl: url, mediaInfo: mediaInfo)
|
||||
}
|
||||
|
||||
/**
|
||||
Remove the first queued audio if one exists. Receive the first URL removed back.
|
||||
|
||||
- Returns the URL of the removed audio.
|
||||
*/
|
||||
public func removeFirstQueuedAudio() -> URL? {
|
||||
guard audioQueued.count != 0 else { return nil }
|
||||
return presenter.handleRemoveFirstQueuedItem()
|
||||
}
|
||||
|
||||
/**
|
||||
Clear the list of queued audio.
|
||||
|
||||
- Returns the list of removed audio URLs
|
||||
*/
|
||||
public func clearAllQueuedAudio() -> [URL] {
|
||||
return presenter.handleClearQueued()
|
||||
}
|
||||
|
||||
/**
|
||||
Resets the player to the state before initializing audio and setting media info.
|
||||
*/
|
||||
|
||||
@@ -132,10 +132,16 @@ extension SAPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Feature to play the current playing audio on repeat until feature is disabled.
|
||||
*/
|
||||
public struct Loop {
|
||||
static var enabled: Bool = false
|
||||
static var playingStatusId: UInt?
|
||||
|
||||
/**
|
||||
Enable feature to play the current playing audio on loop. This will continue until the feature is disabled. And this feature works for both remote and saved audio.
|
||||
*/
|
||||
public static func enable() {
|
||||
enabled = true
|
||||
|
||||
@@ -149,6 +155,9 @@ extension SAPlayer {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
Disable feature playing audio on loop.
|
||||
*/
|
||||
public static func disable() {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
@@ -49,3 +49,37 @@ public struct SALockScreenInfo {
|
||||
self.releaseDate = releaseDate
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Use to add audio to be queued for playback.
|
||||
*/
|
||||
public struct SAAudioQueueItem {
|
||||
public var loc: Location
|
||||
public var url: URL
|
||||
public var mediaInfo: SALockScreenInfo?
|
||||
public var bitrate: SAPlayerBitrate
|
||||
|
||||
/**
|
||||
Use to add audio to be queued for playback.
|
||||
|
||||
- Parameter loc: If the URL for the file is remote or saved on device.
|
||||
- Parameter url: URL of audio to be queued
|
||||
- Parameter mediaInfo: Relevant lockscreen media info for the queued audio.
|
||||
- Parameter bitrate: For streamed remote audio specifiy a bitrate if different from high. Use low bitrate for radio streams.
|
||||
*/
|
||||
public init(loc: Location, url: URL, mediaInfo: SALockScreenInfo?, bitrate: SAPlayerBitrate = .high) {
|
||||
self.loc = loc
|
||||
self.url = url
|
||||
self.mediaInfo = mediaInfo
|
||||
self.bitrate = bitrate
|
||||
}
|
||||
|
||||
/**
|
||||
Where the queued audio is sourced. Remote to be streamed or locally saved on device.
|
||||
*/
|
||||
public enum Location {
|
||||
case remote
|
||||
case saved
|
||||
}
|
||||
}
|
||||
@@ -28,25 +28,6 @@ import AVFoundation
|
||||
import MediaPlayer
|
||||
|
||||
class SAPlayerPresenter {
|
||||
struct QueueItem {
|
||||
var loc: Location
|
||||
var url: URL
|
||||
var mediaInfo: SALockScreenInfo?
|
||||
var bitrate: SAPlayerBitrate
|
||||
|
||||
init(loc: Location, url: URL, mediaInfo: SALockScreenInfo?, bitrate: SAPlayerBitrate = .high) {
|
||||
self.loc = loc
|
||||
self.url = url
|
||||
self.mediaInfo = mediaInfo
|
||||
self.bitrate = bitrate
|
||||
}
|
||||
}
|
||||
|
||||
enum Location {
|
||||
case remote
|
||||
case disk
|
||||
}
|
||||
|
||||
weak var delegate: SAPlayerDelegate?
|
||||
var shouldPlayImmediately = false //for auto-play
|
||||
|
||||
@@ -61,7 +42,7 @@ class SAPlayerPresenter {
|
||||
var durationRef:UInt = 0
|
||||
var needleRef:UInt = 0
|
||||
var playingStatusRef:UInt = 0
|
||||
var audioQueue: [QueueItem] = []
|
||||
var audioQueue: [SAAudioQueueItem] = []
|
||||
|
||||
init(delegate: SAPlayerDelegate?) {
|
||||
self.delegate = delegate
|
||||
@@ -102,11 +83,28 @@ class SAPlayerPresenter {
|
||||
}
|
||||
|
||||
func handleQueueStreamedAudio(withRemoteUrl url: URL, mediaInfo: SALockScreenInfo?, bitrate: SAPlayerBitrate) {
|
||||
audioQueue.append(QueueItem(loc: .remote, url: url, mediaInfo: mediaInfo, bitrate: bitrate))
|
||||
audioQueue.append(SAAudioQueueItem(loc: .remote, url: url, mediaInfo: mediaInfo, bitrate: bitrate))
|
||||
}
|
||||
|
||||
func handleQueueSavedAudio(withSavedUrl url: URL, mediaInfo: SALockScreenInfo?) {
|
||||
audioQueue.append(QueueItem(loc: .disk, url: url, mediaInfo: mediaInfo))
|
||||
audioQueue.append(SAAudioQueueItem(loc: .saved, url: url, mediaInfo: mediaInfo))
|
||||
}
|
||||
|
||||
func handleRemoveFirstQueuedItem() -> URL? {
|
||||
guard audioQueue.count != 0 else { return nil }
|
||||
|
||||
return audioQueue.remove(at: 0).url
|
||||
}
|
||||
|
||||
func handleClearQueued() -> [URL] {
|
||||
guard audioQueue.count != 0 else { return [] }
|
||||
|
||||
let urls = audioQueue.map { item in
|
||||
return item.url
|
||||
}
|
||||
|
||||
audioQueue = []
|
||||
return urls
|
||||
}
|
||||
|
||||
private func attachForUpdates(url: URL) {
|
||||
@@ -146,13 +144,16 @@ class SAPlayerPresenter {
|
||||
return
|
||||
}
|
||||
|
||||
self.isPlaying = isPlaying
|
||||
|
||||
if(self.isPlaying == .paused && self.shouldPlayImmediately) {
|
||||
if(isPlaying == .paused && self.shouldPlayImmediately) {
|
||||
self.shouldPlayImmediately = false
|
||||
self.handlePlay()
|
||||
}
|
||||
|
||||
// solves bug nil == owningEngine || GetEngine() == owningEngine where too many
|
||||
// ended statuses were notified to cause 2 engines to be initialized and causes an error.
|
||||
guard isPlaying != self.isPlaying else { return }
|
||||
self.isPlaying = isPlaying
|
||||
|
||||
if(self.isPlaying == .ended) {
|
||||
self.playNextAudioIfExists()
|
||||
}
|
||||
@@ -248,19 +249,15 @@ extension SAPlayerPresenter {
|
||||
|
||||
delegate?.mediaInfo = nextAudioURL.mediaInfo
|
||||
|
||||
// We need to give a second to clean up the previous engine properly. Deinit takes some time.
|
||||
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { [weak self] (_) in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch nextAudioURL.loc {
|
||||
case .remote:
|
||||
self.handlePlayStreamedAudio(withRemoteUrl: nextAudioURL.url, bitrate: nextAudioURL.bitrate)
|
||||
break
|
||||
case .disk:
|
||||
self.handlePlaySavedAudio(withSavedUrl: nextAudioURL.url)
|
||||
}
|
||||
|
||||
self.shouldPlayImmediately = true
|
||||
switch nextAudioURL.loc {
|
||||
case .remote:
|
||||
handlePlayStreamedAudio(withRemoteUrl: nextAudioURL.url, bitrate: nextAudioURL.bitrate)
|
||||
break
|
||||
case .saved:
|
||||
handlePlaySavedAudio(withSavedUrl: nextAudioURL.url)
|
||||
break
|
||||
}
|
||||
|
||||
shouldPlayImmediately = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'SwiftAudioPlayer'
|
||||
s.version = '6.1.0'
|
||||
s.version = '6.4.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