Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 03c4a7310f | |||
| 9d2d2594a1 |
@@ -8,7 +8,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'SwiftAudioEx'
|
||||
s.version = '0.14.1'
|
||||
s.version = '0.14.2'
|
||||
s.summary = 'Easy audio streaming for iOS'
|
||||
s.description = <<-DESC
|
||||
SwiftAudioEx is an audio player written in Swift, making it simpler to work with audio playback from streams and files.
|
||||
|
||||
@@ -103,7 +103,7 @@ public struct FeedbackCommand: RemoteCommandProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
public enum RemoteCommand {
|
||||
public enum RemoteCommand: CustomStringConvertible {
|
||||
|
||||
case play
|
||||
|
||||
@@ -128,6 +128,23 @@ public enum RemoteCommand {
|
||||
case dislike(isActive: Bool, localizedTitle: String, localizedShortTitle: String)
|
||||
|
||||
case bookmark(isActive: Bool, localizedTitle: String, localizedShortTitle: String)
|
||||
|
||||
public var description: String {
|
||||
switch self {
|
||||
case .play: return "play"
|
||||
case .pause: return "pause"
|
||||
case .stop: return "stop"
|
||||
case .togglePlayPause: return "togglePlayPause"
|
||||
case .next: return "nextTrack"
|
||||
case .previous: return "previousTrack"
|
||||
case .changePlaybackPosition: return "changePlaybackPosition"
|
||||
case .skipForward(_): return "skipForward"
|
||||
case .skipBackward(_): return "skipBackward"
|
||||
case .like(_, _, _): return "like"
|
||||
case .dislike(_, _, _): return "dislike"
|
||||
case .bookmark(_, _, _): return "bookmark"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
All values in an array for convenience.
|
||||
|
||||
@@ -19,7 +19,8 @@ public class RemoteCommandController {
|
||||
weak var audioPlayer: AudioPlayer?
|
||||
|
||||
var commandTargetPointers: [String: Any] = [:]
|
||||
|
||||
private var enabledCommands: [RemoteCommand] = []
|
||||
|
||||
/**
|
||||
Create a new RemoteCommandController.
|
||||
|
||||
@@ -30,10 +31,18 @@ public class RemoteCommandController {
|
||||
}
|
||||
|
||||
internal func enable(commands: [RemoteCommand]) {
|
||||
self.disable(commands: RemoteCommand.all())
|
||||
let commandsToDisable = enabledCommands.filter { command in
|
||||
!commands.contains(where: { $0.description == command.description })
|
||||
}
|
||||
|
||||
self.enabledCommands = commands
|
||||
commands.forEach { (command) in
|
||||
self.enable(command: command)
|
||||
}
|
||||
|
||||
commandsToDisable.forEach { (command) in
|
||||
self.disable(command: command)
|
||||
}
|
||||
}
|
||||
|
||||
internal func disable(commands: [RemoteCommand]) {
|
||||
@@ -44,6 +53,7 @@ public class RemoteCommandController {
|
||||
|
||||
private func enableCommand<Command: RemoteCommandProtocol>(_ command: Command) {
|
||||
center[keyPath: command.commandKeyPath].isEnabled = true
|
||||
center[keyPath: command.commandKeyPath].removeTarget(commandTargetPointers[command.id])
|
||||
commandTargetPointers[command.id] = center[keyPath: command.commandKeyPath].addTarget(handler: self[keyPath: command.handlerKeyPath])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user