GLOBEtech



Playing Sounds in Windows Mobile

After working a bit with the new Windows Mobile 6 SDK i tried to play sounds located on the device. Since there are a few tricky steps, here is the code (C#):


using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace SoundMachine
{
public class Sound
{
[DllImport("CoreDll.dll", EntryPoint = "PlaySound", SetLastError = true)]
private extern static int PlaySound(string szSound, IntPtr hMod, int flags);

private static string soundLocation = @”sounds\”;

private enum SND
{
SYNC = 0×0000,
ASYNC = 0×0001,
NODEFAULT = 0×0002,
MEMORY = 0×0004,
LOOP = 0×0008,
NOSTOP = 0×0010,
NOWAIT = 0×00002000,
ALIAS = 0×00010000,
ALIAS_ID = 0×00110000,
FILENAME = 0×00020000,
RESOURCE = 0×00040004
}

public static void PlaySound(string fileName)
{
PlaySound(Sound.soundLocation + fileName, IntPtr.Zero, (int)(SND.SYNC | SND.FILENAME));
}
}

Its that easy :)


Leave a Comment

(required)

(required)



Formatting your comment
Back to Top | Textarea: Larger | Smaller