Trying to play sounds in console application VB.NET

与世无争的帅哥 提交于 2021-02-17 05:15:51

问题


I want to play a sound file to play in my console application but the following doesn't work:

My.Computer.Audio.Play("[file path string]", AudioPlayMode.Background)

When hovering over "my computer" it brings brings up the error 'Computer' is not a member of 'JapaneseHelper.My'. And when hovering over Audio.PlayMode it says 'AudioPlayMode' is not declared. It may be inaccessible due to its protection level.

I have searched everywhere for this and can't find anything that shows me how to do it, I've only seen instructions for forms applications (When I try to copy what is done in the form app, it doesn't work either). I've tried a couple of "Imports" such as Import System.IO but they didn't fix the issue. I don't want to open a music player, I want it to be played in the background like My.Computer.Audio.Play should do. Is it because you can't do it for a console application maybe? However I don't understand why a console apps wouldn't be able to do it.


回答1:


Did you make sure that your audio file is a .wav? From the Microsoft documentation it looks like you can only play .wav files. According to the documentation it should be possible to play audio files even in a console app.



来源:https://stackoverflow.com/questions/62952660/trying-to-play-sounds-in-console-application-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!