大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
创新互联专注骨干网络服务器租用十多年,服务更有保障!服务器租用,成都服务器托管 成都服务器租用,成都服务器托管,骨干网络带宽,享受低延迟,高速访问。灵活、实现低成本的共享或公网数据中心高速带宽的专属高性能服务器。
For Each FileName As String In IO.Directory.GetFiles("E:\音乐", "*.mp3")
TextBox1.Text = vbNewLine IO.Path.GetFileName(FileName)
Next
End Sub
在.NET里,没有托管的音乐播放器,用API只能播放WAV格式,对于MP3等形式的音频文件,就要依赖于其他控件了,常用的就是
MediaPlayer。使用方法:
在工具箱上点右键,选择“选择项目(Choose Items)”,切到COM选项卡,找到 Windows Media Player, 勾选,确定
在t工具箱上,把刚才加入的MediaPlayer控件,拖放到窗体上
代码:
WindowsMediaPlayer1.URL = "mp3文件路径,支持网络路径"
WindowsMediaPlayer1.Ctlcontrols.play
基本就OK了,至于其他的操作诸如下一曲上一曲暂停停止,直接看 WindowsMediaPlayer1.Ctlcontrols. 里面的方法吧。
我空间有些基本的程序代码、、基本的单个页面代码、、可以供你解剖理解
给你个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("启动完成!")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
添加一个timer控件,隔一秒(Interval = 1000)对照一次本地时间和指定的时间,如果相同就执行铃声,并停止对照。 或者启动时取得本地时间,没一秒把这时间加1秒,直到加到指定的时间执行铃声,并停止加。 播放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"'点击Button1(变成到指定时间就可以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'点击Button2停止播放(根据你自己的情况,比如建一个停止的按钮Private Sub Button2_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Button2.Click Dim cmd As String '播放中音乐停止 cmd = "stop " + aliasName mciSendString(cmd, Nothing, 0, IntPtr.Zero) '关闭 cmd = "close " + aliasName mciSendString(cmd, Nothing, 0, IntPtr.Zero)End Sub