vb.net音乐播放器 winform音乐播放器

VB.NET如何调用并播放项目资源内的WAV文件 。代码是没有错的,但是其中关键是声音文件资源定义字串必须使用根命名空间,不能用程序集名称;还有就是声音文件必须选属性为嵌入资源 。
My.Computer.Audio.Play(My.Resources.xxxmusic1xxx, AudioPlayMode.Background)
简单的播放器用vb.net怎么做啊右击工具箱/部件/WindowsMediaPlayer
//类模块Mmedia
Option Explicit
'-----------------------------------------------------
'Name:MMedia.cls
'Author:Peter Wright, For BG2VB4BG2VB5
'
'Notes:A multimedia class, which when turned
':into an object lets you load and play
':multimedia files, such as sound and
':video.
'-----------------------------------------------------
' -=-=-=- PROPERTIES -=-=-=-
' FilenameDetermines the name of the current file
' LengthThe length of the file (Read Only)
' PositionThe current position through the file
' StatusThe current status of the object (Read Only)
' WaitTrue/False...tells VB to wait until play done
' -=-=-=- METHODS -=-=-=-=-
' mmOpen FilenameOpens the requested filename
' mmCloseCloses the current file
' mmPausePauses playback of the current file
' mmStopStops playback ready for closedown
' mmSeek PositionSeeks to a position in the file
' mmPlayPlays the open file
'-------------------------------------------------------------
' NOTES
' -----
'
' Open a file, then play it. Pause it in response to a request
' from the user. Stop if you intend to seek to the start and
' play again. Close when you no longer want to play the file
'--------------------------------------------------------------
Private sAlias As String' Used internally to give an alias name to
' the multimedia resource
Private sFilename As String' Holds the filename internally
Private nLength As Single' Holds the length of the filename
' internally
Private nPosition As Single' Holds the current position internally
Private sStatus As String' Holds the current status as a string
Private bWait As Boolean' Determines if VB should wait until play
' is complete before returning.
'------------ API DECLARATIONS -------------
'note that this is all one code line:
Private Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" (ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long
Public Sub mmOpen(ByVal sTheFile As String)
' Declare a variable to hold the value returned by mciSendString
Dim nReturn As Long
' Declare a string variable to hold the file type
Dim sType As String
' Opens the specified multimedia file, and closes any
' other that may be open
If sAlias"" Then
mmClose
End If
' Determine the type of file from the file extension
Select Case UCase$(Right$(sTheFile, 3))
Case "WAV"
sType = "Waveaudio"
【vb.net音乐播放器 winform音乐播放器】Case "AVI"
sType = "AviVideo"
Case "MID"
sType = "Sequencer"
Case Else
' If the file extension is not known then exit the subroutine
Exit Sub
End Select
sAlias = Right$(sTheFile, 3)Minute(Now)
' At this point there is no file open, and we have determined the
' file type. Now would be a good time to open the new file.
' Note: if the name contains a space we have to enclose it in quotes
If InStr(sTheFile, " ") Then sTheFile = Chr(34)sTheFileChr(34)
nReturn = mciSendString("Open "sTheFile" ALIAS "sAlias _
" TYPE "sType" wait", "", 0, 0)
End Sub
Public Sub mmClose()
' Closes the currently opened multimedia file
' Declare a variable to hold the return value from the mciSendString
' command
Dim nReturn As Long
' If there is no file currently open then exit the subroutine
If sAlias = "" Then Exit Sub
nReturn = mciSendString("Close "sAlias, "", 0, 0)
sAlias = ""
sFilename = ""
End Sub
Public Sub mmPause()
' Pause playback of the file
' Declare a variable to hold the return value from the mciSendString
' command
Dim nReturn As Long
' If there is no file currently open then exit the subroutine
If sAlias = "" Then Exit Sub
nReturn = mciSendString("Pause "sAlias, "", 0, 0)
End Sub
Public Sub mmPlay()
' Plays the currently open file, from the current position
' Declare a variable to hold the return value from the mciSendString
' command
Dim nReturn As Long
' If there is no file currently open, then exit the routine
If sAlias = "" Then Exit Sub
' Now play the file
If bWait Then
nReturn = mciSendString("Play "sAlias" wait", "", 0, 0)
Else
nReturn = mciSendString("Play "sAlias, "", 0, 0)
End If
End Sub
Public Sub mmStop()
' Stop using a file totally, be it playing or whatever
' Declare a variable to hold the return value from mciSendString
Dim nReturn As Long
' If there is no file currently open then exit the subroutine
If sAlias = "" Then Exit Sub
nReturn = mciSendString("Stop "sAlias, "", 0, 0)
End Sub
Public Sub mmSeek(ByVal nPosition As Single)
' Seeks to a specific position within the file
' Declare a variable to hold the return value from the mciSendString
' function
Dim nReturn As Long
nReturn = mciSendString("Seek "sAlias" to "nPosition, "", 0, 0)
End Sub
Property Get Filename() As String
' Routine to return a value when the programmer asks the
' object for the value of its Filename property
Filename = sFilename
End Property
Property Let Filename(ByVal sTheFile As String)
' Routine to set the value of the filename property, should the programmer
' wish to do so. This implies that the programmer actually wants to open
' a file as well so control is passed to the mmOpen routine
mmOpen sTheFile
End Property
Property Get Wait() As Boolean
' Routine to return the value of the object's wait property.
Wait = bWait
End Property
Property Let Wait(bWaitValue As Boolean)
' Routine to set the value of the object's wait property
bWait = bWaitValue
End Property
Property Get Length() As Single
' Routine to return the length of the currently opened multimedia file
' Declare a variable to hold the return value from the mciSendString
Dim nReturn As Long, nLength As Integer
' Declare a string to hold the returned length from the mci Status call
Dim sLength As String * 255
' If there is no file open then return 0
If sAlias = "" Then
Length = 0
Exit Property
End If
nReturn = mciSendString("Status "sAlias" length", sLength, 255, 0)
nLength = InStr(sLength, Chr$(0))
Length = Val(Left$(sLength, nLength - 1))
End Property
Property Let Position(ByVal nPosition As Single)
' Sets the Position property effectively by seeking
mmSeek nPosition
End Property
Property Get Position() As Single
' Returns the current position in the file
' Declare a variable to hold the return value from mciSendString
Dim nReturn As Integer, nLength As Integer
' Declare a variable to hold the position returned
' by the mci Status position command
Dim sPosition As String * 255
' If there is no file currently opened then exit the subroutine
If sAlias = "" Then Exit Property
' Get the position and return
nReturn = mciSendString("Status "sAlias" position", sPosition, 255, 0)
nLength = InStr(sPosition, Chr$(0))
Position = Val(Left$(sPosition, nLength - 1))
End Property
Property Get Status() As String
' Returns the playback/record status of the current file
' Declare a variable to hold the return value from mciSendString
Dim nReturn As Integer, nLength As Integer
' Declare a variable to hold the return string from mciSendString
Dim sStatus As String * 255
' If there is no file currently opened, then exit the subroutine
If sAlias = "" Then Exit Property
nReturn = mciSendString("Status "sAlias" mode", sStatus, 255, 0)
nLength = InStr(sStatus, Chr$(0))
Status = Left$(sStatus, nLength - 1)
End Property
//窗体fm
Dim m As New Mmedia
Dim fn
Private Sub Command1_Click()
On Error GoTo r
dlg.ShowOpen
fn = dlg.Filename
m.mmOpen fn
r:
If Err Then MsgBox Err.Description
End Sub
Private Sub Command2_Click()
On Error GoTo rp
m.mmPlay
rp:
If Err Then MsgBox Err.Description
End Sub
Private Sub Command3_Click()
On Error GoTo rap
m.mmPause
rap:
If Err Then MsgBox Err.Description
End Sub
Private Sub Command4_Click()
On Error GoTo racp
m.mmStop
racp:
If Err Then MsgBox Err.Description
End Sub
想用VB.NET做个音乐播放器 WMP.DLL控件 有点消耗资源千千静听的组件没有开放api函数 , 你调用了,不知道函数也用不到的啦 。wmp.dll不卡的,你检查一下是不是代码有问题 。
在vb.net上做的播放器加个进度条怎么让他和音乐同步呢??那位vb高手解答下?。。?/h2>你用什么控件做的播放器 WMP的话currentMedia.duration 属性为歌曲总长度Ctlcontrols.currentPosition 为目前播放的进度你可以设置进度条的最大值为总长度然后用计时器不断设置进度条的Value值为Ctlcontrols.currentPosition 就Ok了
关于播放器中的功能(歌词同步),急求VB.NET代码?。?/h2>按照你的说法,应该要用到Ajax,对网页中播放器插件进行帧听,然后再对歌词部分进行处理,百度的Mp3就是这样做的 。
下面就简单的说一下吧
材料:歌曲、歌曲对应的歌词(可以是XML , 当然也可以是歌词专用格式lrc,随便啦,什么文件都可以)、几条简单的JS语句
处理:
1、JSP生成网页的时候 , 将音乐播放器插件的ID命名为WMA,当然,你可以随便命名,只是这里便于说明 。
2、读取XML或LRC内容,利用Ajax加载到id为lrc的div中 。
并将XML或LRC的每行的歌词存到数组testmp3中(此数组当然是二维数组,数据组分别播放时间与歌词内容)
好了,到此,准备工作就做好了,下面就是重点---歌词同步 。
3、相关语句:
一、定义函数getWMAtime
二、利用Interval=setInterval("getWMAtime()",900),意思就是每隔900毫秒调用getWMAtime这个函数,并将其放入Interval中 。
如果要用到“上一曲”“下一曲” , 可以将其做为了一个函数,
将音乐的地址赋给WMA.URL,用WMA.controls.play();播放,用WMA.controls.stop();停止播放,用WMA.controls.pause();暂停播放 。改变了音乐地址后,记得用Ajax载入新的歌词!
另:
getWMAtime函数的内容为读取当前词曲的播放时间
当前的播放时间:WMA.controls.currentPosition;
歌曲总时间:WMA.currentMedia.duration;
读取当前的时候后 , 与数组中时间项进行对比,相同(由于其它原因 , 可能会出现不相同的情况 , 因此则用“=”)则用Ajax对id为lrc的div进行更改,具体怎么改那就随便你咯,一般就是改变一下指定行的颜色 。
如果前当播放时间==歌曲总时间,那么就用clearInterval(Interval) , 停止Interval继续调用 。
好了,一个简单的JS的歌词同步播放器就完工啦
vb.net音乐播放器的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于winform音乐播放器、vb.net音乐播放器的信息别忘了在本站进行查找喔 。

    推荐阅读