项目作者: boring-wozniak

项目描述 :
Change playback device without pain
高级语言: Swift
项目地址: git://github.com/boring-wozniak/AudioDeviceUtil.git
创建时间: 2020-05-20T06:43:01Z
项目社区:https://github.com/boring-wozniak/AudioDeviceUtil

开源协议:MIT License

下载


AudioDeviceUtil

Installation

  1. // In your Package.swift
  2. .package(url: "https://github.com/boring-wozniak/AudioDeviceUtil", from: "0.0.3"),

Usage Example

  1. import AppKit
  2. import AudioObjectUtil
  3. let path = "/path/to/the/sound/you/want/to/play"
  4. guard let sound = NSSound(contentsOfFile: path, byReference: true) else {
  5. fatalError("Failed to create an NSSound object with file path '\(path)'")
  6. }
  7. let deviceName = "As shown in Sound Preferences"
  8. guard let deviceUID = try findDeviceUIDBy(name: deviceName) else {
  9. fatalError("Cannot find a device with name '\(deviceName)'")
  10. }
  11. // This is exactly what this library is about :)
  12. // See https://stackoverflow.com/q/1983984 for more
  13. sound.playbackDeviceIdentifier = deviceUID
  14. if !sound.play() {
  15. fatalError("Cannot play the sound")
  16. }
  17. // Wait until the playback finishes
  18. sleep(UInt32(sound.duration))

My grandma would write it better…🤬

Please, open the issue and describe briefly what exactly is looking troublesome in the code, ideally, with links, references, etc… This is my first gig on the Swift territory so feedback from more experienced developers is very appreciated