A class to play sound on netcf in CSHARP (2)

Source: Internet
Author: User

In the actual test, we found that the playing sound class described in the previous article (a class to play sound on netcf in CSHARP) runs normally in the PDA, but it cannot work in the PC, after a brief analysis of the cause, it is found that the DLL problem occurs. The DLL used for playing the sound on the PC and PDA is different. In PC, It is winmm, while in PDA it is coredll. The project needs to run on both PC and PDA. Therefore, the dynamic judgment function is added to identify whether the program runs on PC or PDA, to load different DLL files to play the sound, the following is an encapsulation of this class:

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. runtime. interopservices;

Namespace minicafe. util
{
Internal class nethelpers
{
[Flags]
Public Enum playsoundflags: int
{
Snd_sync = 0x0000,/* play synchronously (default )*/
Snd_async = 0x0001,/* Play asynchronously */
Snd_nodefault = 0x0002,/* silence (! Default) if sound not found */
Snd_memory = 0x0004,/* pszsound points to a memory file */
Snd_loop = 0x0008,/* loop the sound until next sndplaysound */
Snd_nostop = 0x0010,/* don't stop any currently playing sound */
Snd_nowait = 0x00002000,/* Don't wait if the driver is busy */
Snd_alias = 0x00010000,/* name is a registry alias */
Snd_alias_id = 0x00110000,/* alias is a predefined ID */
Snd_filename = 0x00020000,/* name is file name */
Snd_resource = 0x00040004/* Name Is Resource Name or atom */
}

[Dllimport ("winmm")]
Public static extern bool playsound (string szsound, intptr hmod, playsoundflags flags );
}
Internal class netcfhelpers
{
[Flags]
Public Enum playsoundflags: int
{
Snd_sync = 0x0000,/* play synchronously (default )*/
Snd_async = 0x0001,/* Play asynchronously */
Snd_nodefault = 0x0002,/* silence (! Default) if sound not found */
Snd_memory = 0x0004,/* pszsound points to a memory file */
Snd_loop = 0x0008,/* loop the sound until next sndplaysound */
Snd_nostop = 0x0010,/* don't stop any currently playing sound */
Snd_nowait = 0x00002000,/* Don't wait if the driver is busy */
Snd_alias = 0x00010000,/* name is a registry alias */
Snd_alias_id = 0x00110000,/* alias is a predefined ID */
Snd_filename = 0x00020000,/* name is file name */
Snd_resource = 0x00040004/* Name Is Resource Name or atom */
}

[Dllimport ("coredll")]
Public static extern bool playsound (string szsound, intptr hmod, playsoundflags flags );
}
Public class sound
{
Public static void play (string strfilename)
{
If (Framework. isnetcf)
{
// For PDA
Netcfhelpers. playsound (strfilename, intptr. Zero,
Netcfhelpers. playsoundflags. snd_filename | netcfhelpers. playsoundflags. snd_async );
}
Else
{
// For PC
Nethelpers. playsound (strfilename, intptr. Zero,
Nethelpers. playsoundflags. snd_filename | nethelpers. playsoundflags. snd_async );
}
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.