Public songname As String, aa As String Private Sub getresmp3() aa$ = App.Path & "\" & "111.mp3" If Dir(aa$) = "" Then '如果在本地路径找不到这文件 Dim v, X '开始在本地路径生成这文件 Dim byt() As Byte v = LoadResData(101, "CUSTOM") byt = v '转换为二进制 Open aa$ For Binary As #1 Put #1, 1, byt() Close #1 End If songname = aa$ '定义歌曲名变量, 可以开始调用它来播歌了 End Sub Private Sub WindowsMediaPlayer1_OpenStateChange(ByVal NewState As Long) getresmp3 If Dir(songname) <> "" Then WindowsMediaPlayer1.URL = aa$ End If End Sub
'如果是WAV文件用下面的代码直接就可放的 Private Declare Function sndPlaySoundFromMemory Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Sub PLAYWAV(id as integer)'id 是资源ID号 Dim bArr() As Byte bArr = LoadResData(id, "CUSTOM") sndPlaySoundFromMemory bArr(0), 4 End Sub
Private Sub getresmp3()
aa$ = App.Path & "\" & "111.mp3"
If Dir(aa$) = "" Then '如果在本地路径找不到这文件
Dim v, X '开始在本地路径生成这文件
Dim byt() As Byte
v = LoadResData(101, "CUSTOM")
byt = v '转换为二进制
Open aa$ For Binary As #1
Put #1, 1, byt()
Close #1
End If
songname = aa$ '定义歌曲名变量, 可以开始调用它来播歌了
End Sub Private Sub WindowsMediaPlayer1_OpenStateChange(ByVal NewState As Long)
getresmp3
If Dir(songname) <> "" Then
WindowsMediaPlayer1.URL = aa$
End If
End Sub
Private Declare Function sndPlaySoundFromMemory Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Sub PLAYWAV(id as integer)'id 是资源ID号
Dim bArr() As Byte
bArr = LoadResData(id, "CUSTOM")
sndPlaySoundFromMemory bArr(0), 4
End Sub