Play Sound

From NSIS Wiki
Jump to navigationJump to search
Author: Takhir (talk, contrib)


Description

Requires: System plug-in.

Plays sound using MCIWnd class (MSVFW32.DLL)

The Script

;--------------------------------
; Definitions & Attributes
 
  !define APP_NAME "mci.sound"
  !define SND_NAME "tango.mp3"
  Name "${APP_NAME}"
  OutFile "${APP_NAME}.exe"
 
 
;--------------------------------
; Pages, Interface Settings, Languages
 
  !include "MUI.nsh"
  !insertmacro MUI_PAGE_WELCOME
  !insertmacro MUI_PAGE_INSTFILES
  !insertmacro MUI_PAGE_FINISH
  !insertmacro MUI_LANGUAGE "English"
 
 
;--------------------------------
; User Vars - optional, for WM_CLOSE (if used)
 
  Var hmci
 
 
;--------------------------------
; Required for big packages only
 
ReserveFile "${NSISDIR}\Plugins\system.dll"
ReserveFile "${SND_NAME}"
 
 
;--------------------------------
; Installer Functions
 
Function .onInit
 
  InitPluginsDir
  SetOutPath $PLUGINSDIR
  File "${SND_NAME}"
; this is very beginning of the code, so we may skip Push and Pop for $0 - it is not in use yet
  System::Call 'msvfw32.dll::MCIWndCreate(i 0, i 0,i 0x0070, t "$PLUGINSDIR\${SND_NAME}") i .r0'
; saves MCI window handle for WM_CLOSE in SecDummy
  StrCpy $hmci $0
; Checks format support
  SendMessage $hmci 0x0490 0 0 $0
  IntCmp $0 0 nosup
; if you want mci window to be hidden
  ShowWindow $hmci SW_HIDE
; you can use "STR:play" or "STR:play repeat", but I saw "repeat" problems with midi files 
  SendMessage $hmci 0x0465 0 "STR:play"
nosup:
 
FunctionEnd
 
;--------------------------------
; Installer Sections
 
Section "Dummy Section" SecDummy
 
; add your code here
  Sleep 1000 ; just to show & animate instfiles page, i.e. for DEMO only :)
  Sleep 1000
  Sleep 1000
 
; stops sound at the end of last section, i.e. when 'finish' page is to be displayed
; otherwise it will auto-stop on installer exit.
  SendMessage $hmci ${WM_CLOSE} 0 0
 
SectionEnd

See Also

WinAPI:winmm:PlaySound