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.
A successful call to this method will fire the
SoundLoaded event.
Syntax
|
[Visual Basic]
control.LoadSoundFromMemory (
nPlayer as Integer,
pBuffer as Variant,
nBufferLen as Long
|
|
[C++]
short control.LoadSoundFromMemory (
short nPlayer,
const VARIANT FAR& pBuffer,
long nBufferLen
);
|
|
Parameter
|
Description
|
|
|
|
|
nPlayer
|
Number representing the zero-based index of the player that will load the memory sound
|
|
pBuffer
|
Variant parameter containing the pointer to sound data previously loaded in memory.
|
|
nBufferLen
|
Length in bytes of the given buffer
|
Return value
|
Value
|
Meaning
|
|
|
|
|
Negative value
|
An error occurred (see the LastError property for further error details)
|
|
enumErrorCodes.NOERROR (0)
|
The file has been loaded correctly.
|
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);
}