Sound Guide
Playing pet attention-grabbing sounds using SoundPlayer.
Overview
The UI module bundles 6 sounds to grab a pet's attention. Using the SoundPlayer API, you can encourage a pet to look at the camera during capture.
Available Sounds
Full Sound List
Sound Preview
Click each sound to preview it. Test your pet's reaction!
| Sound | Description | Target | Preview |
|---|---|---|---|
🥔 bagOfChips | Rustling of a chip bag | 🐕🐱 Both | |
🥫 openingCan | Sound of opening a can | 🐕🐱 Both | |
🍚 pouringFood | Sound of pouring food | 🐕🐱 Both | |
🥣 shakeFood | Sound of shaking food | 🐕🐱 Both | |
🧸 squeakyToy | Squeaky toy sound | 🐕 Dog | |
😽 pspspsSound | Pspsps sound | 🐱 Cat |
Basic Usage
1. Play a Random Sound
Automatically selects and plays a sound appropriate for the species.
import PetnowUI
// Random sound for dogs
let player = try? SoundPlayer.play(.random(species: .dog))
// Random sound for cats
let player = try? SoundPlayer.play(.random(species: .cat))2. Play a Specific Sound
Plays a specific sound of your choice.
// Play the squeaky toy sound
let player = try? SoundPlayer.play(.one(name: .squeakyToy))
// Play the pspsps sound
let player = try? SoundPlayer.play(.one(name: .pspspsSound))3. Stop a Sound
To stop a sound, you must keep a reference to the PlayerType object.
// ⚠️ Doing this means you can't call stop()
try? SoundPlayer.play(.one(name: .squeakyToy)) // Return value ignored
// ✅ Keep the player to be able to call stop()
let player = try? SoundPlayer.play(.one(name: .squeakyToy))
// ... later
player?.stop()4. Controlling When Playback Starts (SoundPlayer.make)
SoundPlayer.play(_:) starts playing immediately when called. To control when playback starts yourself, or to prepare a player object in advance, use SoundPlayer.make(_:).
// Create the player only (not yet playing)
let player = try? SoundPlayer.make(.one(name: .bagOfChips))
// Play at the desired time
player?.play()
// Stop
player?.stop()When should you use SoundPlayer.make?
- When you want to prepare a sound in advance and play it on a specific event
- When you need to stop a sound that is playing
- When you need to repeatedly play the same sound
PlayerType Protocol
Both SoundPlayer.play(_:) and SoundPlayer.make(_:) return a SoundPlayer that conforms to the PlayerType protocol.
public protocol PlayerType {
func play() // Play (from the beginning)
func stop() // Stop and rewind to the beginning
}Next Steps
- Basic Usage - The full integration flow
- Customization - Overlay customization