Swiftpack.co - boring-wozniak/AudioDeviceUtil as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by boring-wozniak.
boring-wozniak/AudioDeviceUtil 0.0.3
Change playback device without pain
⭐️ 2
🕓 3 years ago
.package(url: "https://github.com/boring-wozniak/AudioDeviceUtil.git", from: "0.0.3")

AudioDeviceUtil

Installation

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

Usage Example

import AppKit
import AudioObjectUtil

let path = "/path/to/the/sound/you/want/to/play"
guard let sound = NSSound(contentsOfFile: path, byReference: true) else {
    fatalError("Failed to create an NSSound object with file path '\(path)'")
}

let deviceName = "As shown in Sound Preferences"
guard let deviceUID = try findDeviceUIDBy(name: deviceName) else {
    fatalError("Cannot find a device with name '\(deviceName)'")
}

// This is exactly what this library is about :)
// See https://stackoverflow.com/q/1983984 for more
sound.playbackDeviceIdentifier = deviceUID

if !sound.play() {
    fatalError("Cannot play the sound")
}

// Wait until the playback finishes
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

GitHub

link
Stars: 2
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics