添加一個 WindowsMediaPlayer 控件 一句代碼即可播放音樂 AxWindowsMediaPlayer1.URL = "音樂地址"
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站制作、網(wǎng)站設(shè)計、網(wǎng)站頁面設(shè)計、網(wǎng)站優(yōu)化SEO優(yōu)化為一體的專業(yè)網(wǎng)站制作公司,已為成都等多地近百家企業(yè)提供網(wǎng)站建設(shè)服務(wù)。追求良好的瀏覽體驗,以探求精品塑造與理念升華,設(shè)計最適合用戶的網(wǎng)站頁面。 合作只是第一步,服務(wù)才是根本,我們始終堅持講誠信,負(fù)責(zé)任的原則,為您進(jìn)行細(xì)心、貼心、認(rèn)真的服務(wù),與眾多客戶在蓬勃發(fā)展的市場環(huán)境中,互促共生。
在.NET里,沒有托管的音樂播放器,用API只能播放WAV格式,對于MP3等形式的音頻文件,就要依賴于其他控件了,常用的就是
MediaPlayer。使用方法:
在工具箱上點右鍵,選擇“選擇項目(Choose
Items)”,切到COM選項卡,找到
Windows
Media
Player,
勾選,確定
在t工具箱上,把剛才加入的MediaPlayer控件,拖放到窗體上
代碼:
WindowsMediaPlayer1.URL
=
"mp3文件路徑,支持網(wǎng)絡(luò)路徑"
WindowsMediaPlayer1.Ctlcontrols.play
基本就OK了,至于其他的操作諸如下一曲上一曲暫停停止,直接看
WindowsMediaPlayer1.Ctlcontrols.
里面的方法吧。
給你我的程序,自己研究一下吧,我也不是很明白。
Public Class Form1
Private Declare Auto Function PlaySound Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
Const SND_filename As Integer = H20000
Const SND_alias As Integer = H10000
Const SND_sync As Integer = H0
Declare Auto Function waveOutGetNumDevs Lib "winmm.dll" Alias "waveOutGetNumDevs" () As Integer
Declare Auto Function sndPlaySound Lib "winmm.dll" (ByVal filename As String, ByVal options As Integer) As Integer
Private Const SND_memory As Integer = H4
Private Const SND_async As Integer = H1
Private Const proess_domain As String = ""
Const SND_sync1 = H0
Const SND_async1 = H1
Const SND_nodefault = H2
Const SND_loop = H8
Const SND_nostop = H10
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Beep()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strFileName As String = "start.wav"
PlaySound(strFileName, 0, SND_filename)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
PlaySound("systemstart", 0, SND_alias Or SND_sync)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim ret As Long
Dim strfilename As String
strfilename = "start.wav"
ret = sndPlaySound(strfilename.ToCharArray, 0)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim i As Integer
i = waveOutGetNumDevs()
If i 0 Then
MsgBox("可以播放聲音", 64, "檢測")
Else
MsgBox("不能播放聲音", 64, "檢測")
End If
End Sub
End Class
My.Computer.Audio.Play("SoundFile.wav")
SoundFile.wav是你要播放的聲音文件的路徑