NSB.PlaySound("BellToll.wav");
// Make sound loop
bell = NSB.PlaySound("BellToll.wav");
bell.loop=true;
// Stop playing sound
bell.stop()
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
PlaySound ''filename'' | PlaySound ''filename''[,''volume''] | ||
== Description == | == Description == | ||
[[File:PlaySound.png]] | [[File:PlaySound.png]] | ||
Line 6: | Line 5: | ||
PlaySound plays .mp3 and .wav sound files. Playback is immediate, with no on screen controls, making it excellent for user interactions and gaming. | PlaySound plays .mp3 and .wav sound files. Playback is immediate, with no on screen controls, making it excellent for user interactions and gaming. | ||
The files need to be included in the project by adding them to the Project Explorer. | ''volume'' is optional. It's value is from 0 to 1. The default is 1. | ||
The files need to be included in the project by adding them to the Project Explorer. This can be done dragging them from the Finder into the Project Explorer panel. Filenames should not have spaces in them. | |||
PlaySound returns a reference to the sound. You can use this reference to control the sound. | PlaySound returns a reference to the sound. You can use this reference to control the sound. | ||
PlaySound is supported starting with iOS Safari 6 and Chrome 31, so it will work on all current and recent iOS and Android devices. It is not supported in the Android browser or Internet Explorer. | PlaySound is supported starting with iOS Safari 6 and Chrome 31, so it will work on all current and recent iOS and Android devices. It is not supported in the Android browser or Internet Explorer. | ||
Here's a good site with lots of free sound files: http://opengameart.org/art-search-advanced?keys=&field_art_type_tid%5B%5D=13 | |||
== Properties and Methods == | == Properties and Methods == | ||
Line 16: | Line 19: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| soundRef.start() || Start playing the sound. PlaySound auto plays, so this is not normally needed. | | soundRef.start(0) || Start playing the sound. PlaySound auto plays, so this is not normally needed. | ||
|- | |- | ||
| soundRef.stop() || Stop playing the sound | | soundRef.stop(0) || Stop playing the sound. | ||
|- | |- | ||
| soundRef.loop || Make the sound loop endlessly | | soundRef.loop || Make the sound loop endlessly | ||
|} | |} | ||
== Example ( | == Example == | ||
< | |||
<tabber> | |||
JavaScript= | |||
<syntaxhighlight lang="JavaScript"> | |||
NSB.PlaySound("BellToll.wav"); | |||
// Make sound loop | |||
bell = NSB.PlaySound("BellToll.wav"); | |||
bell.loop=true; | |||
// Stop playing sound | |||
bell.stop() | |||
</syntaxhighlight> | |||
|-| | |||
BASIC= | |||
<syntaxhighlight lang="vb.net"> | |||
PlaySound "BellToll.wav" | PlaySound "BellToll.wav" | ||
Make sound loop | ' Make sound loop | ||
bell = PlaySound("BellToll.wav") | bell = PlaySound("BellToll.wav") | ||
bell.loop=True | bell.loop=True | ||
Stop playing sound | 'Stop playing sound | ||
bell.stop() | bell.stop() | ||
</ | </syntaxhighlight> | ||
</tabber> | |||
== Output == | == Output == |
PlaySound filename[,volume]
PlaySound plays .mp3 and .wav sound files. Playback is immediate, with no on screen controls, making it excellent for user interactions and gaming.
volume is optional. It's value is from 0 to 1. The default is 1.
The files need to be included in the project by adding them to the Project Explorer. This can be done dragging them from the Finder into the Project Explorer panel. Filenames should not have spaces in them.
PlaySound returns a reference to the sound. You can use this reference to control the sound.
PlaySound is supported starting with iOS Safari 6 and Chrome 31, so it will work on all current and recent iOS and Android devices. It is not supported in the Android browser or Internet Explorer.
Here's a good site with lots of free sound files: http://opengameart.org/art-search-advanced?keys=&field_art_type_tid%5B%5D=13
soundRef.start(0) | Start playing the sound. PlaySound auto plays, so this is not normally needed. |
soundRef.stop(0) | Stop playing the sound. |
soundRef.loop | Make the sound loop endlessly |
NSB.PlaySound("BellToll.wav");
// Make sound loop
bell = NSB.PlaySound("BellToll.wav");
bell.loop=true;
// Stop playing sound
bell.stop()
PlaySound "BellToll.wav"
' Make sound loop
bell = PlaySound("BellToll.wav")
bell.loop=True
'Stop playing sound
bell.stop()
(sound of a bell tolling)