问题
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