问题描述
DimsrAsStreamReader=NewStreamReader("C:UsersdoyuDesktoptempalarm.wav")DimsoundAsStream=NewMemoryStream(System.Text.Encoding.ASCII.GetBytes(sr.ReadToEnd()))DimyuAsSoundPlayer=NewSoundPlayer(sound)yu.play()paly的时候没异常,但是也没有声音,这是为什么啊?
解决方案
解决方案二:
用MemoryStream
解决方案三:
声明部分:DeclareFunctionFlashWindowLib"user32"(ByValhwndAsInteger,ByValbInvertAsBoolean)AsInteger'宣告APIPrivateDeclareFunctionmciSendStringALib"winmm.dll"_(ByVallpstrCommandAsString,ByVallpstrReturnStringAsString,_ByValuReturnLengthAsInteger,ByValhwndCallbackAsInteger)AsInteger以下是PrivateFunctionPlayMidiFile(ByValMusicFileAsString)AsBooleanIfSystem.IO.File.Exists(MusicFile)ThenmciSendStringA("stopmusic","",0,0)mciSendStringA("closemusic","",0,0)'mciSendStringA("open"&MusicFile&"aliasmusic","",0,0)mciSendStringA("open"&MusicFile&"aliasmusic","",0,0)PlayMidiFile=mciSendStringA("playmusic","",0,0)=0EndIfReturnNothingEndFunctionPrivateFunctionStopMidi()AsBooleanStopMidi=mciSendStringA("stopmusic","",0,0)=0mciSendStringA("closemusic","",0,0)EndFunctionPrivateFunctionPauseMidi()AsBooleanReturnmciSendStringA("pausemusic","",0,0)=0EndFunctionPrivateFunctionContinueMidi()AsBooleanReturnmciSendStringA("playmusic","",0,0)=0EndFunction以下是调用方法:PlayMidiFile(ptShortPath)'播放MP3音樂其中ptShortPath是mp3文件目录地址,注意这个地址中不能包含空格,否则不能正常播放,获取文件目录的短地址可以看以下这篇文章vb.net获取文件短地址方法http://www.spersky.com/post/478.html
解决方案四:
使用文件流播放?还不如直接调用WindowsMediaPlayer播放器控件。AxWindowsMediaPlayer1.URL=My.Computer.FileSystem.CurrentDirectory&"musicPowerOfTheHorde.mp3"‘循环播放AxWindowsMediaPlayer1.settings.setMode("loop",True)