using System; using System.Runtime; using System.Runtime.InteropServices; namespace Tutorial.Sheet3 { public class Mp3Wrapper { public static IntPtr GetStream(string filename) { byte[] bytes = System.Text.Encoding.Default.GetBytes(filename + null); GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); if (Environment.Version.Major == 1) return new IntPtr(handle.AddrOfPinnedObject().ToInt32() + 4); else return handle.AddrOfPinnedObject(); } [DllImport("fmodce.dll", EntryPoint = "FSOUND_Init", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] public static extern bool Initialize(int mixrate, int maxsoftwarechannels, int flags); [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_GetLength", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] public static extern int TrackLength(IntPtr fstream); [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_GetPosition", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] public static extern UInt32 CurrentPosition(IntPtr fstream); [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_Open", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] public static extern IntPtr OpenTrack(IntPtr data, int mode, int offset, int length); [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_Play", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] public static extern int PlayTrack(int channel, IntPtr fstream); [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_SetPosition", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] public static extern bool GoToPosition(IntPtr fstream, UInt32 position); [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_Stop", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] public static extern bool Stop(IntPtr fstream); [DllImport("fmodce.dll", EntryPoint = "FSOUND_Close", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] public static extern void Close(); } }