Sound Guide
Playing pet attention sounds using the playSound function.
Overview
The UI module includes 6 built-in sounds to attract pets' attention. You can use the playSound() function to guide pets to look at the camera during capture.
Available Sounds
Complete Sound List
Sound Preview
Click each sound to preview it. Test your pet's reaction!
| Sound | Description | Target | Preview |
|---|---|---|---|
🥔 bagOfChips | Chip bag crinkling sound | 🐕🐱 Both | |
🥫 openingCan | Can opening sound | 🐕🐱 Both | |
🍚 pouringFood | Food pouring sound | 🐕🐱 Both | |
🥣 shakeFood | Food shaking sound | 🐕🐱 Both | |
🧸 squeakyToy | Squeaky toy sound | 🐕 Dog | |
😽 pspspsSound | Pspsps sound | 🐱 Cat |
Basic Usage
1. Play Random Sound
Automatically selects and plays a species-appropriate sound.
import PetnowUI
// Random sound for dog
let player = try? playSound(.random(species: .dog))
// Random sound for cat
let player = try? playSound(.random(species: .cat))2. Play Specific Sound
Directly select and play desired sound.
// Play squeaky sound
let player = try? playSound(.one(name: .squeakyToy))
// Play pspsps sound
let player = try? playSound(.one(name: .pspspsSound))3. Stop Sound
To stop a sound, you must keep the PlayerType object.
// ⚠️ Cannot call stop() this way
try? playSound(.one(name: .squeakyToy)) // Ignoring return value
// ✅ Keep player to call stop()
let player = try? playSound(.one(name: .squeakyToy))
// ... later
player?.stop()4. Control Playback Timing (makePlayer)
playSound() plays immediately when called. To control playback timing directly or prepare a player object in advance, use the makePlayer(type:) function.
// Create player only (not yet playing)
let player = try? makePlayer(type: .one(name: .bagOfChips))
// Play at desired time
player?.play()
// Stop
player?.stop()When to use makePlayer?
- When you want to prepare a sound in advance and play it on specific events
- When you need to stop a playing sound
- When you need to repeatedly play the same sound
PlayerType Protocol
Both playSound() and makePlayer() return an object conforming to the PlayerType protocol.
public protocol PlayerType {
func play() // Play (from beginning)
func stop() // Stop and rewind to beginning
}Next Steps
- Basic Usage - Complete integration flow
- Customization - Customize overlays