0
0

Below code is the result of my work and other various posts made by this forum’s members (Thanks for this very member who enlightened us about the Ansi/Unicode issue) . I only simplified it.. By the way I did not use any wrapper class or etc but directly imported dll functions. You need to copy fmodce.dll or fmod.dll (respectively for pocketpc and windows) to \windows directory of your system in order to access fmod functions.

just call playMp3Sample() or playMp3Stream() functions to play jules.mp3…

(Make sure that you copy jungle.mp3 or any other media file to the target folder first)

Anyway, here is the working sample code:

public void playMp3Sample()
{
IntPtr ptr = new IntPtr(0);
bool inited = FSOUND_Init(44100, 16, 0);

byte[] filenames = Encoding.Default.GetBytes("\\My Documents\\Personal\\jules.mp3"+'\0'); 
GCHandle hfile = GCHandle.Alloc(filenames, GCHandleType.Pinned); 
IntPtr pfilename = (IntPtr)((int)hfile.AddrOfPinnedObject() + 4); 

ptr =FSOUND_Sample_Load(-1, pfilename, FSOUND_Modes.FSOUND_NORMAL, 0, 0);
FSOUND_PlaySound(-1,ptr);

}

public void playMp3Stream()
{
IntPtr ptr = new IntPtr(0);
bool inited = FSOUND_Init(44100, 16, 0);

byte[] filenames = Encoding.Default.GetBytes("\\My Documents\\Personal\\jules.mp3"+'\0'); 
GCHandle hfile = GCHandle.Alloc(filenames, GCHandleType.Pinned); 
IntPtr pfilename = (IntPtr)((int)hfile.AddrOfPinnedObject() + 4); 

ptr = FSOUND_Stream_Open(pfilename, 0, 0, 0); 
FSOUND_Stream_Play(-1, ptr); 

}

region FMOD DLL IMPORTS

[DllImport( “fmodce.dll”, EntryPoint=”FSOUND_Init” )]
public static extern bool FSOUND_Init( int mixrate, int maxsoftwarechannels, uint flags );

[DllImport( “fmodce.dll”, EntryPoint=”FSOUND_Stream_Open” )]
public static extern IntPtr FSOUND_Stream_Open( IntPtr name_or_data, int mode, int offset, int length );

[DllImport( “fmodce.dll”, EntryPoint=”FSOUND_Stream_Play” )]
public static extern int FSOUND_Stream_Play( int channel, IntPtr stream );

[DllImport( “fmodce.dll”, EntryPoint=”FSOUND_PlaySound”)]
public static extern int FSOUND_PlaySound( int channel, IntPtr stream );

[DllImport( “fmodce.dll”, EntryPoint=”FSOUND_Sample_Load”)]
public static extern IntPtr FSOUND_Sample_Load( int index, IntPtr name,FSOUND_Modes inputmode, int offset, int length );

endregion

[Flags]
public enum FSOUND_Modes : uint
{
FSOUND_16BITS = 0x00000010,
FSOUND_SIGNED = 0x00000100,
FSOUND_MONO = 0x0000002,
FSOUND_NORMAL = (FSOUND_16BITS | FSOUND_SIGNED | FSOUND_MONO)
}
}

Can AKPINAR
real_mca@superonline.com

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.