Search code examples
c#.netwindows-mobilecompact-frameworkmp3

Windows Mobile 6.5 SndPlayAsync - C# wrapper?


I'm implementing mp3 playback on Windows Mobile 6.5. I need to use SndPlayAsync API function since I don't want to block calling thread until the file is played (SndPlaySync blocks until the audio file is playing). Unfortunately the SndPlayAsync method takes sound handle instead of sound file path as parameter so there's a need to open the handle before and release of it after playback. The problem is that I don't have any information about the playback completion in this API. Did anybody use a C# wrapper for this API? Where can I get one? I've looked up OPENNETCF but they seem not to support this API.

Regards


Solution

  • If you are using .NET CF there is no reason to create a wrapper, you can just use the System.Media.SoundPlayer class to handle it. There are several options including PlaySync which will play the sound synchronously.

    For instance:

    string path = "\\Program Files\\SNAP.App.CE\\Content\\5LongLow.wav";
    System.Media.SoundPlayer player = new System.Media.SoundPlayer(path);
    player.PlaySync();
    

    You can also put it in a separate thread if you don't want to block the UI thread.