LoadSoundFromMemory method |
|
Remarks
Loads a sound file stored inside a memory buffer. The sound file can be a stream file (see the LoadSound method for accepted stream formats) or a MOD music file. If the sound is in RAW format use the LoadSoundFromRawMemory method.
A successful call to this method will fire the SoundLoaded event.
Syntax
Return value
Samples
Below you can find a couple of samples that demonstrate how to load a memory sound in Visual Basic 6 and Visual C++ 6: the memory sound has been taken from a .RES resource file using the "identifier" variable.
Visual Basic 6
' the memory buffer must be declared as global Dim bytSound() As Byte
Private Sub Command1_Click() Dim length As Long bytSound = LoadResData(identifier, 10) length = UBound(bytSound)
Amp3dj1.LoadSoundFromMemory 0, VarPtr(bytSound(0)), length Amp3dj1.PlaySound 0 End Sub
Visual C++ 6 with MFC
void CMyDialog::OnButton1() { HINSTANCE hInst = AfxGetResourceHandle(); HRSRC hrsrc = ::FindResource(hInst, MAKEINTRESOURCE (identifier), RT_RCDATA); if (!hrsrc) return;
HGLOBAL hg = LoadResource(hInst, hrsrc); if (!hg) return;
BYTE *pRes = (BYTE*) LockResource(hg); ASSERT(pRes); int iSize = ::SizeofResource(hInst, hrsrc);
VARIANT va; VariantInit (&va); va.vt = VT_BYREF | VT_UI1; va.pbVal = (BYTE *) pRes;
m_ctrlActiveDJ.LoadSoundFromMemory (0, va, iSize); m_ctrlActiveDJ.PlaySound (0); }
|