Private?Sub?Button1_Click(sender?As?Object,?e?As?EventArgs)?Handles?Button1.Click
創(chuàng)新互聯(lián)專注骨干網(wǎng)絡(luò)服務(wù)器租用十多年,服務(wù)更有保障!服務(wù)器租用,成都服務(wù)器托管 成都服務(wù)器租用,成都服務(wù)器托管,骨干網(wǎng)絡(luò)帶寬,享受低延遲,高速訪問(wèn)。靈活、實(shí)現(xiàn)低成本的共享或公網(wǎng)數(shù)據(jù)中心高速帶寬的專屬高性能服務(wù)器。
For?Each?FileName?As?String?In?IO.Directory.GetFiles("E:\音樂(lè)",?"*.mp3")
TextBox1.Text?=?vbNewLine??IO.Path.GetFileName(FileName)
Next
End?Sub
在.NET里,沒(méi)有托管的音樂(lè)播放器,用API只能播放WAV格式,對(duì)于MP3等形式的音頻文件,就要依賴于其他控件了,常用的就是
MediaPlayer。使用方法:
在工具箱上點(diǎn)右鍵,選擇“選擇項(xiàng)目(Choose Items)”,切到COM選項(xiàng)卡,找到 Windows Media Player, 勾選,確定
在t工具箱上,把剛才加入的MediaPlayer控件,拖放到窗體上
代碼:
WindowsMediaPlayer1.URL = "mp3文件路徑,支持網(wǎng)絡(luò)路徑"
WindowsMediaPlayer1.Ctlcontrols.play
基本就OK了,至于其他的操作諸如下一曲上一曲暫停停止,直接看 WindowsMediaPlayer1.Ctlcontrols. 里面的方法吧。
我空間有些基本的程序代碼、、基本的單個(gè)頁(yè)面代碼、、可以供你解剖理解
給你個(gè)udp多播例子,廣播不是很清楚,呵呵
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Inherits System.Windows.Forms.Form
Dim port As String
Dim ipadd As String
Dim ipend As IPEndPoint
Dim sendudp As New UdpClient()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim ipadress As IPAddress
ipadress = IPAddress.Parse(TextBox1.Text)
'sendport = Int32.Parse(TextBox2.Text)
'ipend = New IPEndPoint(ipadress, sendport)
Try
sendudp.JoinMulticastGroup(ipadress)
MessageBox.Show("啟動(dòng)完成!")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
添加一個(gè)timer控件,隔一秒(Interval = 1000)對(duì)照一次本地時(shí)間和指定的時(shí)間,如果相同就執(zhí)行鈴聲,并停止對(duì)照。 或者啟動(dòng)時(shí)取得本地時(shí)間,沒(méi)一秒把這時(shí)間加1秒,直到加到指定的時(shí)間執(zhí)行鈴聲,并停止加。 播放mp3的代碼 System.Runtime.InteropServices.DllImport("winmm.dll", _ CharSet:=System.Runtime.InteropServices.CharSet.Auto) _Private Shared Function mciSendString(ByVal command As String, _ ByVal buffer As System.Text.StringBuilder, _ ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As IntegerEnd FunctionPrivate aliasName As String = "MediaFile"'點(diǎn)擊Button1(變成到指定時(shí)間就可以Private Sub Button1_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles Button1.Click '要播放的文件比如在C:\music.mp3 Dim fileName As String = "C:\music.mp3" Dim cmd As String '打開文件代碼 cmd = "open """ + fileName + """ type mpegvideo alias " + aliasName If mciSendString(cmd, Nothing, 0, IntPtr.Zero) 0 Then Return End If '播放 cmd = "play " + aliasName mciSendString(cmd, Nothing, 0, IntPtr.Zero)End Sub'點(diǎn)擊Button2停止播放(根據(jù)你自己的情況,比如建一個(gè)停止的按鈕Private Sub Button2_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Button2.Click Dim cmd As String '播放中音樂(lè)停止 cmd = "stop " + aliasName mciSendString(cmd, Nothing, 0, IntPtr.Zero) '關(guān)閉 cmd = "close " + aliasName mciSendString(cmd, Nothing, 0, IntPtr.Zero)End Sub