返回首页

介绍

使用Visual Studio目前的能力,你可以做一个简单的音乐播放器非常easily.nbsp,你只需要包括Windows媒体到您的项目的控制和使用them.nbsp;然而,这可能是一个问题IF你没有因为某些原因没有安装媒体Player.nbsp;我的解决办法是使用Windows API提供播放音乐,并落实functionsnbsp MCIstring上的组件,以增加可重用factor.nbsp; 使用代码

创建一个新的VB类库和名称的东西你like.nbsp;粘贴以下代码,并确保您更改类name.nbsp;添加参考Windows.Forms一个新的形式或手动reference.nbsp;之后,建立的类,并通过右击工具栏,NBSP,其中进口到您的项目;选择"选择项",并浏览已编译的DLL。就是这样,现在你可以使用新的组件。
下面的播放按钮的示例代码:

Imports System.Runtime.InteropServices

Imports System.Drawing

Imports System.ComponentModel



Module ImportDll

    <DllImport("winmm.dll", CharSet:=CharSet.Unicode)> _

    Function mciSendString(ByVal lpszCommand As String, ByVal lpszReturnString As String, ByVal cchReturn As Integer, ByVal hwndCallback As Integer) As Integer

    End Function

End Module



Public Class playMusic

    Inherits Windows.Forms.Button

    Friend WithEvents Button2 As System.Windows.Forms.Button



    Dim check As String = "Play"



    Public Sub New()

        Me.Location = New System.Drawing.Point(0, 0)

        Me.Size = New System.Drawing.Size(75, 75)

        Me.BackgroundImageLayout = Windows.Forms.ImageLayout.Stretch

        Me.BackgroundImage = My.Resources.btnPlay

        Me.BackColor = Drawing.Color.Transparent

        Me.FlatStyle = Windows.Forms.FlatStyle.Flat

        Me.FlatAppearance.BorderSize = 0

        Me.FlatAppearance.MouseDownBackColor = Drawing.Color.Transparent

        Me.FlatAppearance.MouseOverBackColor = Drawing.Color.Transparent

    End Sub



    Private Sub InitializeComponent()

        Me.Button2 = New System.Windows.Forms.Button()

        Me.SuspendLayout()

        '<span class="code-comment">

</span>        '<span class="code-comment">Button2

</span>        '<span class="code-comment">

</span>        Me.Button2.Location = New System.Drawing.Point(20, 0)

        Me.Button2.Name = "Button2"

        Me.Button2.Size = New System.Drawing.Size(0, 0)

        Me.Button2.TabIndex = 0

        Me.Button2.Text = "Button2"

        Me.Button2.UseVisualStyleBackColor = True

        Me.ResumeLayout(False)



        Me.BackgroundImage = My.Resources.btnPlay

        Me.Button2.BackgroundImage = My.Resources.btnPlay

    End Sub



    Public Sub playMusic(ByVal path As String)

        mciSendString("play " & path, "", 0, 0)

    End Sub



    Public Sub pauseMusic(ByVal path As String)

        mciSendString("pause " & path, "", 0, 0)

    End Sub



    Public Sub resumeMusic(ByVal path As String)

        mciSendString("resume " & path, "", 0, 0)

    End Sub

End Class 


的代码导入winmm.dll使用MCIstring功能,因此使用这种方法,你可以playnbsp;音乐的情况下直接涉及Windows媒体播放器。 MCIstring本身有一个限制,sonbsp

此代码最初是写一个,你不能播放音乐文件,有一个空间,在他们的名字,如quot;一个music.mp3quot; 景点我assignment.nbsp;如果你的兴趣,你可以采取偷看我的大学网站,并寻找另一ti.ukdw.ac.idnbsp信息; Historynbsp; 2011年5月16日第一Publishednbsp;

回答

评论会员: 时间:2
.