Custom Sound
Lets your app play a custom sound
Lets your app play a custom sound, uploaded once via the WebToNative Dashboard, on demand from your website's JavaScript, and reuses that same sound as an in-app haptic accompaniment. This is a local sound trigger: your JavaScript decides when it plays. It is separate from (but works alongside) a remote push notification playing a custom sound automatically when it arrives — see Custom Notification Sound via OneSignal and Custom Notification Sound via Firebase Cloud Messaging (FCM) for that.
You'll need to import the javascript file in your website before starting from this link.
Platform support: Android and iOS.
How It Works
One uploaded sound file can be used in three different places, and all three reference it by the same name:
Sound.play(soundName)— plays it immediately, triggered directly from your JavaScript (e.g. a chat "message sent" ping, a game effect).Haptics.trigger({ effect, soundName })— plays it alongside a haptic vibration effect, in one call. See Haptic Feedback.A remote push notification — OneSignal or FCM tells the OS to play it automatically when a push arrives. This requires a file with the exact same name to already be uploaded per this page — see OneSignal / FCM for the sending side.
The sound file itself is never sent from your JavaScript or from a push payload — only its name is. It must already be uploaded to your app via the Dashboard before you reference it from any of the three places above.
1. Uploading the Sound File (Dashboard)
Go to your WebToNative Dashboard → Add-ons → Notification → OS Notification Sound and upload the sound file under the platform's sound setting. Android and iOS each have their own separate upload field — uploading for one platform does not make the file available on the other, so upload the same audio to both fields if you want consistent behavior across platforms.
Reference name: the name you pass to
Sound.play/soundNameis derived from the uploaded file's name, minus its extension.Format: only
.mp3and.wavfiles can be uploaded — these are the only supported formats on both platforms.Extension:
.mp3is the default — if you callSound.play("your_sound_name")without an extension,.mp3is assumed automatically, so you don't need to pass anything if you uploaded an.mp3file. If you uploaded a.wavfile, you must pass the extension explicitly —Sound.play("your_sound_name.wav")— or the lookup will assume.mp3and fail to find it.
Changes take effect on your app's next build — if you're testing on a device already running an older build, rebuild/reinstall after uploading a new or changed sound file.
JavaScript API Reference
Sound.play
Plays an uploaded sound immediately.
Parameters:
soundName
String
Yes
Name of the uploaded sound file, with or without extension (see Uploading the Sound File). If no extension is given, .mp3 is assumed.
This function does not take a callback — it is fire-and-forget, with no response to read. If the named sound isn't found or fails to play, it fails silently on both platforms — see Troubleshooting below.
Haptics.trigger with a sound
Haptics.trigger also accepts an optional soundName, so one call can trigger a haptic effect and an uploaded sound together. Full parameter/effect reference lives on the Haptic Feedback page — this is the sound-specific addition to that same function.
Parameters:
effect
String
No
The vibration pattern to play. See Haptic Feedback for supported values.
soundName
String
No
Name of an uploaded sound file to play alongside the haptic effect, using the exact same lookup rules as Sound.play above. Omit it to trigger the haptic effect only.
Internally this plays the sound through the same path as
Sound.play— there's no behavioral difference between callingSound.play("x")directly versus passingsoundName: "x"here, other than the haptic effect firing at the same time.
Common Patterns
Playing a Sound Only on Notification-Relevant Actions
Reserve Sound.play for actions that should feel like a native alert (message received in an open chat, item added to cart) rather than every UI tap — pair it with a haptic effect for actions that also warrant one:
Troubleshooting
Nothing plays, no error in the console: this is expected if the sound isn't found — both platforms fail silently with no callback to JavaScript. Double-check that the file was uploaded to the correct platform's field on the Dashboard, that you've rebuilt/reinstalled since uploading, and that the name (and extension, if you passed one) matches exactly — see Uploading the Sound File.
Frequently Asked Questions
Last updated