Copyright © 2005-2018 MultiMedia Soft

LoadSoundFromMemory method

Previous pageReturn to chapter overviewNext page

Remarks

 

Loads a sound file stored in memory. 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 invokes the CallbackForPlayersEvents delegate with the nEvent parameter set to EV_SOUND_LOADED.

 

 

Syntax

 

[Visual Basic]

Public Function LoadSoundFromMemory (

nPlayerIndex as Int16,

pBuffer() as Byte,

nBufferLength as Int32

) as enumErrorCodes


 

[C#]

public enumErrorCodes LoadSoundFromMemory (

Int16 nPlayerIndex,

byte[] pBuffer,

Int32 nBufferLength

);


 

[C++]

public: enumErrorCodes LoadSoundFromMemory (

Int16 nPlayerIndex,

unsigned char __gc[] pBuffer,

Int32 nBufferLength

);


 

 

Parameter

Description

 

 

nPlayerIndex

Number representing the zero-based index of the player that will load the memory sound

pBuffer

Buffer containing sound data

nBufferLength

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 method call was successful.

 

 

Sample

 

Below you can find a couple of samples that demonstrate how to load a sound stored in memory in Visual Basic.NET and Visual C# : in these samples the file is taken from a file and its contents are stored in memory.

 

Visual Basic.NET

 

' declare the memory buffer (cannot be a local variable)

Dim m_byteBuffer() As Byte

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 Dim openFileDialog1 As New OpenFileDialog

 If openFileDialog1.ShowDialog() <> DialogResult.OK Then

     Return

 End If

 

 ' put the song file into a stream

 Dim streamFile As FileStream

 streamFile = New FileStream(openFileDialog1.FileName, FileMode.Open)

 Dim binReader As BinaryReader

 binReader = New BinaryReader(streamFile)

 

 ' reallocate the memory buffer space and store the song

 ReDim m_byteBuffer(streamFile.Length)

 binReader.Read(m_byteBuffer, 0, streamFile.Length)

 

 If AudioDjStudio1.LoadSoundFromMemory(0, m_byteBuffer, streamFile.Length) = AudioDjStudio.enumErrorCodes.NOERROR Then

     ' do domething

     ....

 End If

End Sub

 

 

Visual C#.NET

 

// declare the memory buffer (cannot be a local variable)

byte[] m_byteBuffer = null;

 

private void buttonLoad1_Click(object sender, System.EventArgs e)

{

 OpenFileDialog openFileDialog1 = new OpenFileDialog();

 if (openFileDialog1.ShowDialog() != DialogResult.OK)

     return;

 

 // put the song file into a stream

 FileStream      streamFile = new FileStream (openFileDialog1.FileName, FileMode.Open);

 BinaryReader    binReader = new BinaryReader (streamFile);

 

 //  allocate the memory buffer space and store the song

 m_byteBuffer = new byte[streamFile.Length];

 binReader.Read (m_byteBuffer, 0, (int) streamFile.Length);

 

 // load song from memory buffer

 if (audioDjStudio1.LoadSoundFromMemory (0, m_byteBuffer, (Int32) streamFile.Length) == enumErrorCodes.NOERROR)

 {

     // do something

     ...

 }

}