WinAPI:winmm:PlaySound: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
m (→‎PlaySound Function: Spelling/case (ref. <http://en.wikipedia.org/wiki/WAV>).)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{PageAuthor|sag47}}
== PlaySound Function ==
== PlaySound Function ==
This will play a wav file. It is a function that is part of winmm.dll It is very easy to play the sound too.
References:
* http://msdn2.microsoft.com/en-us/library/ms712879.aspx
* [http://publicsvn.songbirdnest.com/browser/trunk/tools/win32/nsis/examples/System/System.nsh?rev=5425#L143 NSIS Data Structures Examples]
This will play a WAV file. It is a function that is part of winmm.dll. It is very easy to play the sound too.


=== Asynchronous Playing ===
=== Asynchronous Playing ===
The following code will start playing the wav file as your installer continues. This is good if you want a little entertainment with a long install.
The following code will start playing the WAV file as your installer continues. This is good if you want a little entertainment with a long install.
<highlight-nsis>Function .onInit
<highlight-nsis>Function .onInit
   InitPluginsDir
   InitPluginsDir
Line 15: Line 19:


==== Stopping the Sound ====
==== Stopping the Sound ====
Simply call the following code anywhere in your installer (has to be within a function, macro, or section). The sound/music will immediately stop once it is called.
Simply call the following code anywhere in your installer (has to be within a function, macro, or section). The sound/music will immediately stop once it is called.
<highlight-nsis>System::Call 'winmm::PlaySound(i, i, i) b'</highlight-nsis>
<highlight-nsis>System::Call 'winmm::PlaySound(i, i, i) b'</highlight-nsis>



Latest revision as of 20:42, 6 May 2013

Author: sag47 (talk, contrib)


PlaySound Function

References:

This will play a WAV file. It is a function that is part of winmm.dll. It is very easy to play the sound too.

Asynchronous Playing

The following code will start playing the WAV file as your installer continues. This is good if you want a little entertainment with a long install.

Function .onInit
  InitPluginsDir
  File /oname=$PLUGINSDIR\sound.wav "batcave.wav"
 
; Play the sound or song
  StrCpy $0 "$PLUGINSDIR\sound.wav"  ; location of the wav file
  IntOp $1 "SND_ASYNC" || 1
  System::Call 'winmm::PlaySound(t r0, i 0, i r1) b'
FunctionEnd

Stopping the Sound

Simply call the following code anywhere in your installer (has to be within a function, macro, or section). The sound/music will immediately stop once it is called.

System::Call 'winmm::PlaySound(i, i, i) b'

Synchronous Playing

This will play the sound but the installer won't continue until the sound is finished playing.

Function .onInit
  InitPluginsDir
  File /oname=$PLUGINSDIR\sound.wav "batcave.wav"
 
; Play the sound or song
  StrCpy $0 "$PLUGINSDIR\sound.wav"
  System::Call 'winmm::PlaySound(t r0, i, i) b'
FunctionEnd

keyword "Play Sound"

WinAPI:winmm