Conversation
|
|
|
|
||
| /// Plays a prepared sound. | ||
| /// | ||
| /// Remote playback is best-effort and is skipped if remote routing is unavailable. |
There was a problem hiding this comment.
There's no way to propagate the error atm, right?
| public class SoundPlayer: Loggable, @unchecked Sendable { | ||
| // MARK: - Public | ||
|
|
||
| public static let shared = SoundPlayer() |
There was a problem hiding this comment.
Have you considered an explicit lifecycle here (e.g. coupled with AudioManager, Room etc.)
There was a problem hiding this comment.
Nit: if this is a singleton, can leverage https://www.avanderlee.com/concurrency/global-actor/
| /// Releases the associated audio session requirement. | ||
| /// | ||
| /// Releasing the same handle multiple times is a no-op. | ||
| public func release() throws { |
There was a problem hiding this comment.
This probably should be called on deinit.
pblazej
left a comment
There was a problem hiding this comment.
I think this is more than enough for V1, good point about gradual evolution.
Trivia I'd address before merging:
- rename
urltofileURLstill (just self-documenting) - auto-release session on handle's
deinit - adding
globalActor
Follow-ups:
playOnceaddition (no hard feelings)?- lazy pool
- caching converted audio
For me as a consumer the biggest confusion comes from the fact that .remote cannot be played without mic track - which is not clear just reading the APIs. I get the best-effort tradeoff, maybe we can escalate the log to .warning at least / or rename the enum more aggressively:
public enum Destination: Sendable {
case local
case remoteIfAvailable // ?
case localAndRemoteIfAvailablethat could be an OptionSet as well e.g.
public struct Destination: OptionSet, Sendable {
public static let local = Destination(rawValue: 1 << 0)
public static let remoteIfAvailable = Destination(rawValue: 1 << 1)
}you pass like this:
options: .init(destination: [.local, .remoteIfAvailable])
options: .init(destination: .local)|
Thanks @pblazej , will work on a second pass of polishing this up. |
Conveniently prepare and play short audio clips locally and/or for remote participants.
Remote playback is best-effort and usually requires the microphone/WebRTC input path to be published.
Example: livekit-examples/swift-example#89