C #. Net sonnd class

Source: Internet
Author: User

 

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

Namespace pal_mes.brlibrary
{
Class cplaysound
{
/// <Summary>
/// Invoke window API for playing sound file
/// </Summary>
/// <Param name = "lpszsoundname"> filename with its full path </param>
/// <Param name = "fsound"> flag </param>
/// <Returns> </returns>
[Dllimport ("winmm. dll")]
Protected static extern bool sndplaysound (string lpszsoundname, fusound fsound );
/// <Summary>
/// Enum sound Properties
/// </Summary>
Protected Enum fusound
{
Snd_sync = 0,
Snd_async = 1,
Snd_nodefault = 2,
Snd_memory = 4,
Snd_loop = 8
};
/// <Summary>
/// Invoke system API function to play sound file
/// </Summary>
/// <Param name = "strfilewithfullpath"> filename and its absolute path </param>

Public void playsound (string strfilewithfullpath)
{
Try
{
Bool brtn = sndplaysound (strfilewithfullpath, fusound. snd_nodefault );
}
Catch
{
}
}
}
}

 

Client application: cplaysound sound = new cplaysound ();

Sound. playsound (application. startuppath + @ "\ oo.wav ");

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.