Play Sound: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
== Description == | == Description == | ||
'''Requires:''' [[System | '''Requires:''' [[System plug-in]]. | ||
Plays sound using MCIWnd class ( | Plays sound using MCIWnd class (MSVFW32.DLL) | ||
== The Script == | == The Script == | ||
Line 44: | Line 44: | ||
Function .onInit | Function .onInit | ||
InitPluginsDir | InitPluginsDir | ||
SetOutPath $PLUGINSDIR | SetOutPath $PLUGINSDIR | ||
Line 50: | Line 50: | ||
; this is very beginning of the code, so we may skip Push and Pop for $0 - it is not in use yet | ; 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' | 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 | ; if you want mci window to be hidden | ||
ShowWindow $ | ShowWindow $hmci SW_HIDE | ||
; you can use "STR:play" or "STR:play repeat", but I saw "repeat" problems with midi files | ; you can use "STR:play" or "STR:play repeat", but I saw "repeat" problems with midi files | ||
SendMessage $ | SendMessage $hmci 0x0465 0 "STR:play" | ||
nosup: | |||
FunctionEnd | FunctionEnd | ||
;-------------------------------- | ;-------------------------------- | ||
Line 71: | Line 74: | ||
; stops sound at the end of last section, i.e. when 'finish' page is to be displayed | ; 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 | ; otherwise it will auto-stop on installer exit. | ||
SendMessage $hmci ${WM_CLOSE} 0 0 | SendMessage $hmci ${WM_CLOSE} 0 0 | ||
Line 78: | Line 80: | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category: | == See Also == | ||
[[WinAPI:winmm:PlaySound]] | |||
[[Category:System Plugin Examples]] |
Latest revision as of 14:02, 20 August 2007
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