Playing MP3 with windows mobile

It took me quite a time finding useful hints on how to play MP3 with Windows Mobile. So here is what was found:

public class Sound
{
static IntPtr hSound = IntPtr.Zero;
const int SND_SCOPE_PROCESS = 0x1;[DllImport("aygshell.dll")]
static extern uint SndOpen(string pszSoundFile, ref IntPtr phSound);

[DllImport("aygshell.dll")]
static extern uint SndPlayAsync(IntPtr hSound, uint dwFlags);

[DllImport("aygshell.dll")]
static extern uint SndClose(IntPtr hSound);

[DllImport("aygshell.dll")]
static extern uint SndStop(int SoundScope, IntPtr hSound);

public static void Play(string fileName)
{
// filename must be absolute
// e.g. <a href="/////Program">\\Program</a> Files\\Test\\phone.mp3
SndOpen(fileName, ref hSound);
SndPlayAsync(hSound, 0);
}

public static void Stop()
{
SndClose(hSound);
SndStop(SND_SCOPE_PROCESS, IntPtr.Zero);
}
}

Tested with Windows Mobile 6.

Playing MP3 with windows mobile

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s