Quantcast

Pustanje wav-ova u VB6

fakpuppet

Zainteresovan član
Poruka
145
Bond:
Vako! Najprostiji kod bi izgledao kao ovo ispod:
deklarises PlaySound API, dve konstante i dva Sub-a u modulu (znachi ne mora posebno u modul ali uopsteno nije losha praksa)...

WAVModul:
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Private Const SND_ASYNC = &H1
Private Const SND_LOOP = &H8

Public Sub playFile(ByVal strWAVPath As String, bLoop As Boolean)
Dim lFlag As Long

lFlag = IIf(bLoop, SND_ASYNC Or SND_LOOP, SND_ASYNC)

PlaySound strWAVPath, 0, lFlag
End Sub

Public Sub stopPlayback()
PlaySound vbNullString, 0, 0
End Sub

I sada fajl pustas pozivajuci sub playFile kojem prosledjujes znachi adresu fajla i Boolean bLoop koji ti omogucava da napravis petlju i da se playback ponavlja a stopiras playback pozivajuci drugi sub stopPlayback. Npr. analogno tvojoj potrebi u kodu:

If a + b = 10 Then playFile "C:\polusatno svrshavanje divlje svinje.wav", False

Mislim ono... API je bolja alternativa natrpavanju projekata vishefunkcionalnim i pre svega masivnim ActiveX kontrolama za obavljanje jednostavnog zadatka kakav je pustiti jedan debilni wav.

LL&P,

fakpuppet
 

Rallyaa

Početnik
Poruka
23
Ukljuci kontrolu Microsoft Multimedia Control 6.0. Napravi jednu na formi i otkucaj.

Private Sub Command1_Click()
MMcontrol1.Command = "Close"
MMcontrol1.DeviceType = "WaveAudio"
MMcontrol1.FileName = "\lokacija\ime_fajla.wav"
MMControl1.Command = "Open"
MMcontrol1.Command = "Prev"
MMcontrol1.Command = "Play"
End Sub
 
Top