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]] plug-in.
'''Requires:''' [[System plug-in]].


Plays sound using MCIWnd class (MS VFW DLL)  
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 $0 SW_HIDE
   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 $0 0x0465 0 "STR:play"
   SendMessage $hmci 0x0465 0 "STR:play"
; saves MCI window handle for WM_CLOSE in SecDummy
nosup:
  StrCpy $hmci $0
 
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. Finally you can skip Var hmci, it's
; otherwise it will auto-stop on installer exit.
; StrCpy and SendMessage below if you don't want silence on the 'finish' page.
   SendMessage $hmci ${WM_CLOSE} 0 0
   SendMessage $hmci ${WM_CLOSE} 0 0


Line 78: Line 80:


</highlight-nsis>
</highlight-nsis>
[[Category:Other Products Handling Functions]]
== 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

See Also

WinAPI:winmm:PlaySound