简体   繁体   English

C#中的等效代码是什么

[英]what is the equivalent code in c#

My.Computer.Audio.Play(strAudioFilePath, AudioPlayMode.Background) My.Computer.Audio.Play(strAudioFilePath,AudioPlayMode.Background)

This is vb.net code i want to write similar code in c#. 这是vb.net代码,我想在c#中编写类似的代码。 i tried converting this code in c# but it is not working, does anyone have have any idea? 我尝试在C#中转换此代码,但无法正常工作,有人知道吗?

SoundPlayer simpleSound = new SoundPlayer(strAudioFilePath);
simpleSound.Play();

You will have to Add reference to Microsoft.VisualBasic for an exactly equivalent code like this. 您将必须添加对Microsoft.VisualBasic的引用,以获得完全相同的代码,例如这样。

Microsoft.VisualBasic.Devices.Audio audio = new Audio();
audio.Play(strAudioFilePath, AudioPlayMode.Background);

Although there are other options which don't involve Audio class. 尽管还有其他选项不涉及Audio类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM