Petnow LogoPetnow

Sound Guide

Playing pet attention-grabbing sounds with SoundPlayer.


Before starting this guide, complete Basic Usage.

Overview

The UI module includes 6 built-in sounds to attract pets' attention. SoundPlayer in io.petnow.ui.sound plays them, and it is independent of the camera — you can use it on a guide screen before capture starts, not only during capture.

CameraController.playSound() is deprecated since 1.5.0

CameraController.playSound() / stopSound() still work and are kept for source compatibility, but they raise a deprecation warning. Use SoundPlayer instead.

Available Sounds

Complete Sound List

Sound Preview

Click each sound to preview it. Test your pet's reaction!

The preview names below are sample audio file names; in code, use the constant in the SoundType column.

SoundSoundTypeDescriptionTargetPreview
🥔 bagOfChipsBAG_OF_CHIPSChip bag rustling sound🐕🐱 Both
🥫 openingCanOPENING_CANCan opening sound🐕🐱 Both
🍚 pouringFoodPOURING_FOODFood pouring sound🐕🐱 Both
🥣 shakeFoodSHAKERSFood shaking sound🐕🐱 Both
🧸 squeakyToyDOG_ONLY_SQUEAKY_TOYSqueaky toy sound🐕 Dogs
😽 pspspsSoundCAT_ONLY_PSPSPSPspsps sound🐱 Cats

Basic Usage

1. Create and prepare the player

prepare() loads the samples and is a suspend function, so call it from a coroutine. Until it finishes, play() does nothing.

import io.petnow.ui.sound.SoundPlayer
import io.petnow.ui.sound.SoundType

private val sounds = SoundPlayer(context)
private var soundHandle: Int = -1

lifecycleScope.launch {
    sounds.prepare()
}

2. Play a Random Sound

Plays one of the loaded sounds at random. RANDOM does not take the species into account on Android, so pass a specific SoundType when the sound has to match the species.

soundHandle = sounds.play(SoundType.RANDOM)

play() returns a handle for stopping the sound, or -1 when the player is not prepared yet or no sample is mapped.

3. Play a Specific Sound

Directly select and play the sound you want.

// Can opening sound
soundHandle = sounds.play(SoundType.OPENING_CAN)

4. Stop a Sound

sounds.stop(soundHandle)

5. Release the player

Free the native resources when the screen goes away. The instance cannot be used afterwards, so create a new one if you need sound again.

override fun onDestroy() {
    sounds.release()
    super.onDestroy()
}

On this page