扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
首先列出目录下的所有MP3文件并赋给某个数组变量,然后再播放。没时间帮你写,只能说一下方法了 Private Sub Command1_Click() Dim file As String file = Dir("C:\windows\*.mp3") '改成绝对路径,这个变量换成数组的,利用FOR来赋值,得到正确的文件路径后就再播放就可以了,自己完善一下吧 Do While file "" Print file file = Dir Loop End Sub
我们提供的服务有:成都做网站、成都网站建设、成都外贸网站建设、微信公众号开发、网站优化、网站认证、漠河ssl等。为上1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的漠河网站制作公司
你用什么控件做的播放器 WMP的话currentMedia.duration 属性为歌曲总长度 Ctlcontrols.currentPosition 为目前播放的进度 你可以设置进度条的最大值为总长度 然后用计时器不断设置进度条的Value值为Ctlcontrols.currentPosition 就Ok了
代码是没有错的,但是其中关键是声音文件资源定义字串必须使用根命名空间,不能用程序集名称;还有就是声音文件必须选属性为嵌入资源。
My.Computer.Audio.Play(My.Resources.xxxmusic1xxx, AudioPlayMode.Background)
不明白你为什么要二进制读取声音文件,VB可以直接调用API播放声音文件,不需要你二进制来读取声音文件的。
Private
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA"
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub PlayWavFile(strFileName As String, PlayCount As Long, JianGe As Long)
'strFileName 要播放的文件名(带路径)
'playCount 播放的次数
'JianGe 多次播放时,每次的时间间隔
If Len(Dir(strFileName)) = 0 Then Exit Sub
If PlayCount = 0 Then Exit Sub
If JianGe 1000 Then JianGe = 1000
DoEvents
sndPlaySound strFileName, 16 + 1
Sleep JianGe
Call PlayWavFile(strFileName, PlayCount - 1, JianGe)
End Sub
Private Sub Form_Click()
PlayWavFile "C:\aaa.wav", 1, 1000 '参数:播放文件,播放次数,播放间隔
End Sub
获得用户桌面相对路径的方法和系统里的不一样
'函数及变量声明
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
Const MAX_LEN = 200
Dim sTmp As String * MAX_LEN
Dim pidl As Long
'调用
SHGetSpecialFolderLocation 0, DESKTOP, pidl 'DESKTOP指的就是用户桌面
SHGetPathFromIDList pidl, sTmp
My.Computer.Audio.Play (Left(sTmp, InStr(sTmp, Chr(0)) - 1) "\vb.net语言学习\data riyu\sound\a.wav")
工具栏里选择"添加,删除组件"
选择com组件
选择"Windows Media Player "
然后在界面上加入这个组件
代码
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Const DATA_FILE_EXTENSION As String = ".mp3"
Dim dlgFileDialog As New OpenFileDialog
With dlgFileDialog
.Filter = DATA_FILE_EXTENSION _
" files (*" DATA_FILE_EXTENSION "|*" DATA_FILE_EXTENSION
.FilterIndex = 1
.RestoreDirectory = True
If .ShowDialog() = DialogResult.OK Then
'Play the sound file
Me.AxWindowsMediaPlayer1.URL = dlgFileDialog.FileName
End If
End With
End Sub
参考资料中可以看到很详细的步骤
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流