VB制作MP3MP4播放器源代码-简单实用.

合集下载

vb利用MediaPlayer制作MP3播放器

vb利用MediaPlayer制作MP3播放器
cmdPlay.Enabled = False
cmdPause.Enabled = True
cmdContinue.Enabled = False
cmdStop.Enabled = True
Exit Sub
handler:
MsgBox "未选择媒体文件。", vbOKOnly, "错误信息"
cmdStop.BackColor = vbRed
cmdNext.BackColor = vbRed
cmdContinue.Enabled = False
cmdPause.Enabled = False
cmdStop.Enabled = False
Text1.Text = "本播放器支持各种音乐格式。谢谢使用。 土人。"
Private Sub cmdContinue_Click()
Text1.SetFocus
MediaPlayer1.Play
cmdPlay.Enabled = False
cmdPause.Enabled = True
cmdContinue.Enabled = False
End Sub
End Sub �
Text1.BackColor = vbBlack
Text1.ForeColor = vbYellow
End Sub
'播放
Private Sub cmdPlay_Click()
Text1.SetFocus
On Error GoTo handler
With CommonDialog1
.FileName = ""

音频播放器代码-代码大全

音频播放器代码-代码大全

音频播放器代码-代码大全播放器样式和代码1.简易播放器一(手动) 主要音频格式:rm,ra,ram,mp3简易播放器(自动播放)代码,提取方法:右击,全选,复制<center><embed src="音频绝对地址" width=200 height=30 controls=ControlPanel loop=true autostart=true volume=100 type=audio/x-pn-realaudio-plugin Initfn=load-types mime-types=mime.types></center>2.简易播放器二(手动) 主要格式wma,mp3简易播放器二(自动播放)代码.提取方法:右击,全选,复制<center><EMBED style="FILTER: xray(); WIDTH: 200px; HEIGHT: 30px" src="音频绝对地址" type=audio/x-mpegurl volume="0" loop="-1" autostart="true" allowscriptaccess="never"></EMBED></center>3.多功能播放器(手动)各类格式音视频 (rm等除外)多功能播放器(自动播放)代码,提取方法:右击,全选,复制(如果是视频文件,请将以下代码里的值改为height=350)<center><OBJECT id=phx height=45 width=350 classid=clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6><PARAM NAME="URL" VALUE="音视频绝对地址"><PARAM NAME="rate" VALUE="1"><PARAM NAME="balance" VALUE="0"><PARAM NAME="currentPosition" VALUE="0"><PARAM NAME="defaultFrame" VALUE=""><PARAM NAME="playCount" VALUE="1"><PARAM NAME="autoStart" VALUE="-1"><PARAM NAME="currentMarker" VALUE="0"><PARAM NAME="invokeURLs" VALUE="-1"><PARAM NAME="baseURL" VALUE=""><PARAM NAME="volume" VALUE="78"><PARAM NAME="mute" VALUE="0"><PARAM NAME="uiMode"VALUE="full"><PARAM NAME="stretchToFit" VALUE="0"><PARAM NAME="windowlessVideo" VALUE="0"><PARAM NAME="enabled" VALUE="-1"><PARAM NAME="enableContextMenu" VALUE="-1"><PARAM NAME="fullScreen" VALUE="0"><PARAM NAME="SAMIStyle" VALUE=""><PARAM NAME="SAMILang" VALUE=""><PARAM NAME="SAMIFilename" VALUE=""><PARAM NAME="captioningID" VALUE=""><PARAM NAME="enableErrorDialogs" VALUE="0"><PARAM NAME="_cx" VALUE="8811"><PARAM NAME="_cy" VALUE="1217"></OBJECT></CENTER>4.微软简易播放器(手动)音频格式:mp3,wma等微软播放器(自动播放)代码,提取方法:右击,全选,复制<P align=center><EMBED src="音频绝对地址" width=320 height=45 type=audio/mpeg autostart="0"></EMBED></P>5.标签型播放器(手动播放)音频格式 mp3,wma标签型播放器(自动播放)代码:代码提取方法:右击,全选,复制<DIV align=center><EMBED src="音频绝对地址" width=300 height=140 type=audio/x-ms-wma balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="false" autostart="true" animationatstart="false" transparentatstart="true"></div>注:1,以上显示的播放器均设置为手动播放,即:autostart="0".如需自动播放请设置autostart="true".2,以上各播放器代码里均设置为自动播放,即.autostart="true",如需手动播放请设置autostart="0"样式和代码1.简易播放器一(手动) 主要音频格式:rm,ra,ram,mp3简易播放器(自动播放)代码,提取方法:右击,全选,复制<center><embed src="音频绝对地址" width=200 height=30 controls=ControlPanel loop=true autostart=true volume=100 type=audio/x-pn-realaudio-plugin Initfn=load-types mime-types=mime.types></center>2.简易播放器二(手动) 主要格式wma,mp3简易播放器二(自动播放)代码.提取方法:右击,全选,复制<center><EMBED style="FILTER: xray(); WIDTH: 200px; HEIGHT: 30px" src="音频绝对地址" type=audio/x-mpegurl volume="0" loop="-1" autostart="true" allowscriptaccess="never"></EMBED></center>3.多功能播放器(手动)各类格式音视频 (rm等除外)多功能播放器(自动播放)代码,提取方法:右击,全选,复制(如果是视频文件,请将以下代码里的值改为height=350)<center><OBJECT id=phx height=45 width=350 classid=clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6><PARAM NAME="URL" VALUE="音视频绝对地址"><PARAM NAME="rate" VALUE="1"><PARAM NAME="balance" VALUE="0"><PARAM NAME="currentPosition" VALUE="0"><PARAM NAME="defaultFrame" VALUE=""><PARAM NAME="playCount" VALUE="1"><PARAM NAME="autoStart" VALUE="-1"><PARAM NAME="currentMarker" VALUE="0"><PARAM NAME="invokeURLs" VALUE="-1"><PARAM NAME="baseURL" VALUE=""><PARAM NAME="volume" VALUE="78"><PARAM NAME="mute" VALUE="0"><PARAM NAME="uiMode" VALUE="full"><PARAM NAME="stretchToFit" VALUE="0"><PARAM NAME="windowlessVideo"VALUE="0"><PARAM NAME="enabled" VALUE="-1"><PARAM NAME="enableContextMenu" VALUE="-1"><PARAM NAME="fullScreen" VALUE="0"><PARAM NAME="SAMIStyle" VALUE=""><PARAM NAME="SAMILang" VALUE=""><PARAM NAME="SAMIFilename" VALUE=""><PARAM NAME="captioningID" VALUE=""><PARAM NAME="enableErrorDialogs" VALUE="0"><PARAM NAME="_cx" VALUE="8811"><PARAM NAME="_cy" VALUE="1217"></OBJECT></CENTER>4.微软简易播放器(手动)音频格式:mp3,wma等微软播放器(自动播放)代码,提取方法:右击,全选,复制<P align=center><EMBED src="音频绝对地址" width=320 height=45 type=audio/mpeg autostart="0"></EMBED></P>5.标签型播放器(手动播放)音频格式 mp3,wma标签型播放器(自动播放)代码:代码提取方法:右击,全选,复制<DIV align=center><EMBED src="音频绝对地址" width=300 height=140 type=audio/x-ms-wma balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="false" autostart="true" animationatstart="false" transparentatstart="true"></div>注:1,以上显示的播放器均设置为手动播放,即:autostart="0".如需自动播放请设置autostart="true".2,以上各播放器代码里均设置为自动播放,即.autostart="true",如需手动播放请设置autostart="0"。

vb自制媒体播放器

vb自制媒体播放器

自制媒体播放器1、因为我们需要使用到MediaPlayer控件,所以刚开始就要右击工具面板并在部件添加窗口里选择“Windows MediaPlayer”来添加这个控件,同时还要添加“Co mmonDialog”控件。

2、在窗口设计器中创建一个MediaPlayer控件、五个Command Button控件和一个CommonDialog控件。

3、将Form1的Caption属性更改为“小叮当的媒体播放器”。

4、分别将五个Command Button控件的Caption属性分别命名为“暂停”、“播放”、“停止”、“选择”和“退出”,然后把它们按照一定的位置放好。

5、选中CommonDialog控件之后,在右边属性的“Filter”对话框中输入“*.RMV B|*.wav)|*.wav|MIDI(*.mid)|*.mid|MPEG(*.mpeg)|*.mpeg|DAT(*.dat)|*.dat| AVI(*.avi)|*.avi|MP3(*.mp3)|*.mp3”的文件过滤选项,这样就可以支持各种常见的媒体影像文件了。

小蘑菇:看起来和真正的MediaPlayer差不多呀,还蛮有专业水准的呢。

小叮当:是呀,这全要归功于MediaPlayer控件,下面就是代码编写部分内容了:1、首先要双击Form1窗口,并选择“通用”对象,输入下面的通用代码:Option ExplicitDim playfilename As String/定义播放文件的名称Dim playposition As Double/定义当前播放的位置2、双击“暂停”按键并输入下列代码:Private Sub Command1_Click()Command1.Enabled = False/暂停按键失效MediaPlayer1.Pause/暂停播放playposition = MediaPlayer1.CurrentPosition/当前的播放位置End Sub3、双击“播放”按键并输入下列代码:Private Sub Command2_Click()Command1.Enabled = True/暂停按键有效Command3.Enabled = True/停止按键有效MediaPlayer1.filename = playfilename/播放媒体文件名称MediaPlayer1.SelectionStart = playposition/当前播放的位置MediaPlayer1.Play/播放媒体文件End Sub 4、双击“停止”按键并输入下列代码:Private Sub Command3_Click()playposition = 0/停止播放Command3.Enabled = False/停止按键无效Command1.Enabled = False/暂停按键无效Command2.Enabled = True/播放按键有效MediaPlayer1.Stop/停止播放End Sub5、双击“选择”按键并输入下列代码:Private Sub Command4_Click()CommonDialog1.showopen/打开文件对话框playfilename = CommonDialog1.filename/记录播放文件名playposition = 0/第一次打开文件时候,播放位置为0 End Sub6、双击“退出”按键并输入下列代码:Private Sub Command5_Click()Unload Me/卸载窗口End/结束程序End Sub代码全部输入完毕之后,运行程序后按下“选择”按键,此时会弹出打开文件对话框供你选择需要播放的文件。

VB制作MP3MP4播放器源代码-简单实用.

VB制作MP3MP4播放器源代码-简单实用.

媒体播放器很多,但是定制的广告令人生厌,还是自己动手做一个和WindowsMediaPlayer 播放器效果一样的吧,直接用微软提供的WindowsMediaPlayer 控件就可以,下边简单介绍一下WindowsMediaPlayer 控件的用法。

这里用VB 开发,用VC 任然是一样的,只不过VC 中进行类操作,属性和方法的使用是完全一样,下边只列出部分功能,以起抛砖引玉的作用。

有兴趣的朋友可以继续完善哦!制作步骤:一、控件添加这是必须的,VB 中在工具箱中点击右键添加,选中WindowsMediaPlayer ,然后工具箱中会出现一个我们非常熟悉的WindowsMediaPlayer 图标。

二、界面在工具箱里添加WindowsMediaPlayer 控件,然后新建一个窗体,将WindowsMediaPlayer 控件加进去,可以用控件按钮(打开、播放、暂停、停止等),也可以自己设计(如本文中)。

三、添加代码如下Dim flag As BooleanPrivate Sub Form_Load(With WindowsMediaPlayer1.uiMode = "full"End WithEnd Sub' 播放暂停Private Sub Command1_Click( flag = Not flagWith WindowsMediaPlayer1 If flag = True Then Command1.Caption = "pause" .Controls.PlayElseCommand1.Caption = "play" .Controls.pauseEnd IfEnd WithEnd Sub' 停止Private Sub Command2_Click( With WindowsMediaPlayer1 .Controls.StopEnd WithEnd SubPrivate Sub Command4_Click( '打开文件With CommonDialog1' .Filter = "avi (*.avi|*.avi".ShowOpenEnd WithWith WindowsMediaPlayer1' .URL = App.Path + "\017 喜欢你没道理张韶涵.mp3".Controls.StopEnd With' 快进Private Sub Command3_Click(With WindowsMediaPlayer1.Controls.currentPosition = .Controls.currentPosition + 10End WithEnd Sub' 快退Private Sub Command5_Click(With WindowsMediaPlayer1.Controls.currentPosition = .Controls.currentPosition - 10 End WithEnd Sub。

如何用VB实现MP3播放功能

如何用VB实现MP3播放功能

如何用VB实现MP3播放功能? 2004-9-29黑客基地本文作者曾经读过不少关于如何用VB实现播放MP3格式音乐文件的文章。

这些文章所介绍的方法都具有一个相同的特点,即要借助某个第三方提供的具有专门的MP3解码功能的控件。

能不能直接利用VB自身所提供的多媒体控件来实现MP3播放功能呢?答案是肯定的。

任何一种编码格式的音、视频文件都要通过其相应的解码器解码后才能实现播放的目的,MP3也不例外。

Microsoft在Win9x系统中已经内置了MP3的解码驱动,因此我们完全可以利用它直接对MP3进行解码,从而实现播放MP3的目的。

在编码上,我们只需在C:\windows\system.ini文件的[MCI]项目中添加命令行:mp3audio=mciqtz.drv 使VB自身所提供的多媒体控件能够正确调用相应的解码器对MP3进行解码就足够了。

下面就让我们利用VB自带的MMControl控件做一个MP3播放器实例。

实现步骤如下:一、绘制窗体:(见下图)1.新建一个工程,在窗体中加入MMControl控件,名称为MP3Player(通过在工具箱上单击鼠标右键弹出的菜单中选择[部件],并在弹出的部件对话框中选中Microsoft Multimedia Control 6.0 可以将MMControl控件添加至工具箱中备用)。

CommonDialog控件,名称为CommonDialog1。

两个Label控件,名称分别为TitleWnd、FileNameWnd。

2.利用菜单编辑器建立菜单[文件],创建两个菜单项,一为[打开](名为file_open),一为[退出](名为file_exit)二、在工程中加入一个模块,编写播放MP3的过程代码以备调用三、程序编码1.form1中的代码:2.模块中的代码:关于MMControl控件的详细使用方法请参考MSDN,本程序调试环境:Win98SE,Visual Basic 6.0企业版。

用VBA在Excel中播放MP3音乐

用VBA在Excel中播放MP3音乐

用VBA在Excel中播放MP3音乐在VBA中通过调用API函数mcisendstring,可以播放MP3格式的音乐。

下面是VBA代码,我们可以将它放入模块中,方法是在VBA编辑器中单击菜单“插入→模块”,在代码窗口中输入下列代码。

Option ExplicitPublic Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA"(ByVal lpstrCommand As String, ByVal lpstrReturnString As S tring,ByVal uReturnLength As Long, ByVal hwndCallback As Long) As LongPublic Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA"(ByVal lpszLongPath As String, ByVal lpszShortPath As String , ByVal cchBuffer As Long) As LongPrivate Function ConvShortFilename(ByVal strLongPath$) As StringDim strShortPath$If InStr(1, strLongPath, " ") ThenstrShortPath = String(LenB(strLongPath), Chr(0))GetShortPathName strLongPath, strShortPath, Len(strShort Path)ConvShortFilename = Left(strShortPath, InStr(1, strShortPat h, Chr(0)) - 1)ElseConvShortFilename = strLongPathEnd IfEnd FunctionPublic Sub MMPlay(ByRef FileName As String)FileName = ConvShortFilename(FileName)mciSendString "close " & FileName, vbNullString, 0, 0mciSendString "open " & FileName, vbNullString, 0, 0mciSendString "play " & FileName, vbNullString, 0, 0End SubPublic Sub MMStop(ByRef FileName As String)FileName = ConvShortFilename(FileName)mciSendString "stop " & FileName, vbNullString, 0, 0mciSendString "close " & FileName, vbNullString, 0, 0End Sub然后,可以在VBA中调用上述代码。

VB MP3播放器

VB MP3播放器

VB MP3播放器今天,我们将制作一个MP3播放器。

程序运行时,可以选择MP3文件,选择左右声道声音,总共播放所需的时间等。

程序运行结果如图所示。

运行结果技术要点●注册Mp3Play控件●获得MP3文件的播放总时间●设置左右声道的声音●获得MP3文件的总帧数实现过程■新建项目打开Visual ,选择“新建项目”,在项目类型窗口中选择“Visual Basic项目”,在模板窗口中选择“Windows应用程序”,在名称域中输入“Mp3Play”,然后选择保存路径。

单击“确认”。

■添加控件向当前窗体添加七个Label控件,其中四个作为说明之用,其余三个分别用于显示MP3文件的播放时间、总帧数和文件名称。

鼠标右击工具箱,选择“自定义工具箱”,在弹出的对话框中选择Com组件,选中“Microsoft Common Dialog Control6.0”、“Microsoft Common Controls 6.0”、单击“浏览”,选中文件Mp3play.ocx,这时会在“”选项卡中出现“Dialog-Media Mp3Play ActiveX Control Module”一项。

添加一个CommonDialog控件、三个Slider控件和一个Mp3PlayCtrl控件。

■设置属性切换到“属性栏”,对窗体上的控件设置属性如下所示。

属性表■添加代码' 选择mp3文件Private Sub button1_Click(ByVal eventSender As System.Object, ByVal eventArgs AsSystem.EventArgs) Handles button1.ClickDim totaltimes As IntegerAXCommonDialog1.ShowOpen()If Len(AXCommonDialog1.FileName) = 0 Then Exit SubErr.Number = Mp3Play1.Open(AXCommonDialog1.FileName, "")' 取得mp3文件的总时间totaltimes = Mp3Play1.TotalTimelbltotaltime.Text = "播放时间:" & Str(totaltimes \ 60000) & ":" & Str(Int((totaltimesMod 60000) / 1000))lblmp3name.Text = AXCommonDialog1.FileName' 取得mp3文件的左右声道音量leftvolume = Mp3Play1.GetVolumeLeftrightvolume = Mp3Play1.GetVolumeRightsldPos.Value = 0' 取得mp3文件的总帧数sldPos.Max = Mp3Play1.FrameCountlblframe.Text = "共" & sldPos.Max & "帧"button2.Enabled = Truebutton3.Enabled = Truebutton4.Enabled = TrueEnd Sub' 开始播放Private Sub button2_Click(ByVal eventSender As System.Object, ByVal eventArgs AsSystem.EventArgs) Handles button2.ClickMp3Play1.Play()End Sub' 暂停播放Private Sub button3_Click(ByVal eventSender As System.Object, ByVal eventArgs AsSystem.EventArgs) Handles button3.ClickMp3Play1.Pause()End Sub' 停止播放Private Sub button4_Click(ByVal eventSender As System.Object, ByVal eventArgs AsSystem.EventArgs) Handles button4.ClickMp3Play1.Stop()End Sub' 程序启动时,必须进行注册,否则不能正确播放' 设置左右声道默认值为中间值Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs AsSystem.EventArgs) Handles MyBase.LoadMp3Play1.Authorize("LightBringer", "1441658209")SldLeft.Value = 50SldRight.Value = 50' 在没有选择mp3文件之前,令播放、暂停、停止按钮不可用button2.Enabled = Falsebutton3.Enabled = Falsebutton4.Enabled = FalseEnd Sub' 改变左声道的音量Private Sub SldLeft_Change(ByVal eventSender As System.Object, ByVal eventArgs AsSystem.EventArgs) Handles SldLeft.ChangeMp3Play1.SetVolume(leftvolume * SldLeft.Value / 100, rightvolume *SldRight.Value / 100)End Sub' 改变播放mp3文件的位置Private Sub sldPos_Change(ByVal eventSender As System.Object, ByVal eventArgs AsSystem.EventArgs) Handles sldPos.ChangeMp3Play1.Seek(sldPos.Value)Mp3Play1.Play()End Sub■运行结果单击菜单“调试|启动”或单击图标运行程序。

用VB6.0制作多媒体播放器

用VB6.0制作多媒体播放器
playfilename = commondialog1.filename ‘记录播放文件名 playposition = 0’第一次打开文件时候,播放位置为 0 end sub 3.2.3 播放文件 在工程 1-form1(code)窗口中选择对象 command2 事件选择 click,然后输入以代码:
用 vb6.0 制作多媒体播放器
平山县回舍中学 郜兵山 本文设计并实现了一个能播放多媒体文件的播放器,并提供了 vb6.0 下的源代码。 关键词:vb6.0 播放器 activex 控件 1、引言 windows media player 控件支持的文件类型比较丰富,可以播放 wav、mid、 mp3、wma、aif、asf、mpeg、mpg、avi、mov、dat、rmi 等多媒体文件。本文介绍了在 vb6.0 环境下,利用 windows media player 控件,实现选择本地电脑上多媒体文件,并进行播放的功 能。 2、设计思路 2.1 选择需要播放的多媒体文件 通过对通用对话框控件(comdlg32.ocx)有关属性的设置,可以实现按选择的多媒体类型, 在列表中显示的多媒体文件列表,用户可以在该列表中选择一个文件进行播放。 2.2 实现多媒体文件的选择、播放、暂停、继续、停止和程序的退出 在该播放器中,单击“选择”按钮,打开“打开”对话框;在该对话框中,可以实现以 下三点选择:第一、选择要播放的多媒体文件的类型;第二、选择本地电脑中保存的多媒体 文件的位置;第三、在显示的多媒体文件列表中,选择当前要播放的多媒体文件。单击“播 放”按钮,播放用户当前选中的多媒体文件;单击“暂停”按钮,播放暂时停止,同时记下 该文件的播放位置;同时暂停按钮变成继续按钮,单击“继续”按钮,还接着原来播放的位 置往下播放文件。单击“停止”按钮,停止播放。单击“关闭”按钮,退出程序。 3、功能实现 3.1 界面布局 3.1.1 新建一个工程 执行开始→所有程序→visual basic 6.0 精简版→visual basic 6.0 精简版命令,打开 新建工程对话框,如下图所示.

vb课程设计-影音播放器 源代码

vb课程设计-影音播放器 源代码

'添加MediaPlayer1 CommonDialog1 Timer1 Command1(0) Command1(1) Command1(2)'Mediaplayer1 请使用MSDXM.OCX 那个控件Dim songname$Private Sub Form_Load()Command1(0).Caption = "选歌播放"Command1(1).Caption = "暂停"Command1(2).Caption = "停止"Command1(1).Enabled = FalseCommand1(2).Enabled = FalseTimer1.Interval = 100Timer1.Enabled = FalseEnd SubPrivate Sub Form_Unload(Cancel As Integer)Call stopmusicEndEnd SubPrivate Sub Command1_Click(Index As Integer)Select Case IndexCase 0On Error GoTo errchoiceWith CommonDialog1.CancelError = True.InitDir = App.Path.Filter = "音乐文件|*.mp3;*.mid;*.wav;*.wma;*.rid".Action = 1End WithIf CommonDialog1.FileName <> "" Thensongname = CommonDialog1.FileNameCall playmusic(songname)End IfCase 1If Command1(1).Caption = "暂停" ThenMediaPlayer1.PauseCommand1(1).Caption = "继续"ElseMediaPlayer1.PlayCommand1(1).Caption = "暂停"End IfCase 2Call stopmusicEnd Selecterrchoice:If Err > 0 Then Exit Sub '选择了取消End SubSub playmusic(sname As String)On Error GoTo errhandler'playState:integer;播放状态0=关闭停止,1=暂停, 2=播放,6=正在缓冲'0=mpClosed 1=mpPaused 2=mpPlying 6=mpWaitingMediaPlayer1.FileName = snameIf MediaPlayer1.PlayState = 1 Or MediaPlayer1.PlayState = 2 Then Call stopmusic MediaPlayer1.PlayCommand1(1).Caption = "暂停"Command1(1).Enabled = TrueCommand1(2).Enabled = TrueTimer1.Enabled = Trueerrhandler:If Err > 0 Then MsgBox "歌曲格式不支援或文件受损"End SubSub stopmusic()MediaPlayer1.SelectionEnd = -1MediaPlayer1.CurrentPosition = 0MediaPlayer1.StopCommand1(1).Caption = "暂停"Command1(1).Enabled = FalseCommand1(2).Enabled = FalseTimer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()If MediaPlayer1.PlayState = mpStopped Then Call stopmusicEnd Sub。

用VB编写的Mp3播放器源代码

用VB编写的Mp3播放器源代码

Public Class Form1Dim soundname As String()Dim i As IntegerDim j, l As BooleanDim k As IntegerDim filename As String'取歌曲的名字Dim path As String()Dim s, m As IntegerDim luj As StringDim count As Integer'用来声明选择歌曲的数目Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadi = 0j = Falsel = FalseLabel2.Text = "歌曲名:"Label3.Text = "歌曲演唱者:"Label4.Text = "歌曲描述:"Label5.Text = "歌曲类型:"Label6.Text = "歌曲大小:"End SubPrivate Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Clickselectsound()End SubPrivate Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.ScrollMe.AxWindowsMediaPlayer1.settings.volume = TrackBar1.ValueEnd SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickIf Timer1.Enabled = False ThenTimer1.Enabled = TrueElseTimer1.Enabled = FalseEnd IfIf i = 0 ThenMe.AxWindowsMediaPlayer1.Ctlcontrols.pause()i = 1Button3.Text = "继续"Exit SubEnd IfIf i = 1 ThenMe.AxWindowsMediaPlayer1.Ctlcontrols.play()Button3.Text = "暂停"i = 0Exit SubEnd IfEnd SubPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.TickDim string1, ss, sss As Stringstring1 =ListBox1.SelectedItem.ToString.Substring(stIndexOf("\") + 1)filename = string1.Substring(0, stIndexOf("."))luj = ListBox1.SelectedItem.ToString.Substring(0,stIndexOf(".")) + ".lrc"ss = Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPositionStringbel1.Text = ssIf Dir(luj) <> Nothing ThenDim fr As System.IO.StreamReader = New System.IO.StreamReader(luj,System.Text.Encoding.Default)sss = fr.ReadLine '我们读取的第一行歌词While (sss <> "")If (stIndexOf(ss) <> -1) Then'时间匹配了歌词中的时间Me.TextBox1.Text = sss.Substring(stIndexOf("]") + 1)Form2.TextBox1.Text = Me.TextBox1.TextEnd Ifsss = fr.ReadLineEnd WhileElseTextBox1.Text = "Not Find! 请从网上下载歌词!"Form2.TextBox1.Text = "Not Find! 请从网上下载歌词!"End IfLabel1.Text = "当前进度:" + Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString End SubPrivate Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e AsSystem.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.ScrollMe.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = Me.HScrollBar1.Value / 1000 * Me.AxWindowsMediaPlayer1.currentMedia.durationEnd SubPrivate Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.ClickMe.AxWindowsMediaPlayer1.Ctlcontrols.fastForward()End SubPrivate Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles ListBox1.SelectedIndexChangedMe.AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex)Me.AxWindowsMediaPlayer1.Ctlcontrols.play()Label2.Text = "歌曲名:" + Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Title")Label3.Text = "歌曲演唱者:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Author") Label4.Text = "歌曲描述:" +Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Description")Label5.Text = "歌曲类型:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileType") Label6.Text = "歌曲大小:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize") Timer1.Start()End SubPrivate Sub playsound()Timer1.Stop()TrackBar1.Value = Me.AxWindowsMediaPlayer1.settings.volumeIf j = False ThenMe.AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex) ElseIf j = True Thenk = (ListBox1.SelectedIndex + 1) Mod soundname.LengthMe.AxWindowsMediaPlayer1.URL = ListBox1.Items(k)j = FalseEnd IfListBox1.SelectedIndex = kMe.AxWindowsMediaPlayer1.Ctlcontrols.play()Label2.Text = "歌曲名:" + Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Title")Label3.Text = "歌曲演唱者:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Author") Label4.Text = "歌曲描述:" +Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Description")Label5.Text = "歌曲类型:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileType") Label6.Text = "歌曲大小:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize") Timer1.Start()End SubPrivate Sub selectsound()Dim open As New OpenFileDialogDim i As IntegerWith open.Filter = "所有mp3文件(*.mp3)|*.mp3|所有wma文件(*.wma)|*.wma".Multiselect = True.Title = "请选择歌曲"End WithIf (open.ShowDialog = Windows.Forms.DialogResult.OK) Thensoundname = open.FileNamesFor i = 0 To soundname.GetUpperBound(0)ListBox1.Items.Add(soundname(i))NextListBox1.SelectedIndex = 0End IfEnd SubPrivate Sub AxWindowsMediaPlayer1_Enter(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles AxWindowsMediaPlayer1.EnterIf AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded Thenj = TrueTimer2.Start()End IfEnd SubPrivate Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tickplaysound()Timer2.Stop()End SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickTimer1.Stop()If ListBox1.SelectedIndex = 0 ThenMe.AxWindowsMediaPlayer1.URL = ListBox1.Items(soundname.Length - 1)ListBox1.SelectedIndex = (soundname.Length - 1)ElseMe.AxWindowsMediaPlayer1.URL = ListBox1.Items((ListBox1.SelectedIndex Mod soundname.Length) - 1)ListBox1.SelectedIndex = (ListBox1.SelectedIndex Mod soundname.Length) - 1 End IfMe.AxWindowsMediaPlayer1.Ctlcontrols.play()Label2.Text = "歌曲名:" + Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Title")Label3.Text = "歌曲演唱者:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Author") Label4.Text = "歌曲描述:" +Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Description")Label5.Text = "歌曲类型:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileType") Label6.Text = "歌曲大小:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize") Timer1.Start()End SubPrivate Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.ClickForm2.Show()End SubEnd Class。

VBA播放MP3歌曲的代码

VBA播放MP3歌曲的代码

VBA播放MP3歌曲的代码可以用来做背景音乐。

使用方法:打开word、excel等然后按Alt+F11 在打开的窗口中粘贴下面代码:Private Declare Function m ciS endString Lib "winmm.dll" Alias "mciSendStringA" (ByV al lpstrCommand As String, ByV al lpstrReturnString As String, ByV al uReturnLength As Long, ByV al hwndCallback As Long) As LongDim sMCI As String * 255Dim sMP3Dim iNum As IntegerPublic Function Blank(ByV al szString As String) As StringDim l As Integerl = InStr(szString, Chr(0))If l > 0 ThenBlank = Left(szString, l - 1)ElseBlank = szStringEnd IfEnd FunctionPrivate Sub CommandButton1_Click()mciSendString "close OpenFile", 0&, 0, 0End SubPrivate Sub CommandButton2_Click()mciSendString "status OpenFile mode", sMCI, 255, 0If Blank(sMCI) <> "playing" ThenmciSendString "close OpenFile", 0&, 0, 0mciSendString "open """ & "D:\aw\情非得已.mp3"" alias OpenFile type MPEGVideo", 0&, 0, 0mciSendString "play OpenFile", 0&, 0, 0iNum = iNum + 1'If iNum > UBound(sMP3) Then Timer1.Enabled = FalseEnd IfEnd Sub在文档中添加两个按钮控件就行了。

用VB6制作mp3播放器

用VB6制作mp3播放器

用VB6.0制作一个MP3播放器,给出代码谢谢2008-03-13 17:36lkmu | 分类:多媒体软件| 浏览3813次分享到:2008-03-14 13:19 提问者采纳用VB制作一个简单的MP3播放器用VB制作一个简单的MP3播放器利用API函数[mciSendString]可以轻松实现MP3音乐文件的播放。

下面这段程序实现了MP3播放的大部分常规操作,对其稍加修改,做一个100KB 大小的MP3播放器轻而易举启动VB程序,在窗体上放置6个命令按钮,三个标签,一个公用对话框、一个进度条、一个状态栏和一个计时器,窗本的布置请参考附图按钮"Open MP3 File"是用来打开对话框选择MP3文件,其他5个按钮分别为Play(播放)、Pause(暂停)、Stopplay(停止播放)、Back(向后跳跃)、Prew(向前跳跃)。

Label1用来表示歌曲当前时间;label2放在时度条的最左边,Caption 属性为"00:00";lable3放在时度条的右边,用来表示歌曲总长。

下面就可以编写代码了。

首先在窗体的"通用声明"部分声明函数Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrRetumString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As LongDim mfn As String下面就是各个对象的代码了:Private Sub Form_load()mfn = ""play.Enabled = Falsepause.Enabled = Falsestopplay.Enabled = Falseback.Enabled = Falseprew.Enabled = FalseTimer1.Enabled = FalseTimer1.Interval = 500End SubPrivate Sub open_Click()On Error GoTo errWith CommonDialog1.CancelError = True.Filter = "音乐文件|*.mp3;*.wav;*.mid".Flags = cdlOFNNoChangeDir And cdlOFNPathMustExist.Action = 1stopplay_Click '停止按钮同时可以设备初始化mfn = .FileName '这个程序中文件名一定不能带空格Form1.Caption = .FileNameplay.Enabled = TrueEnd Withplay_ClickExit Suberr:End SubPrivate Sub play_Click()On Error Resume NextDim t As Longt = mciSendString("open " + mfn, 0&, 0, 0) 'Open后边的空格一定不能丢Dim ret As String * 128t = mciSendString("status " + mfn + " length", ret, 128, 0)'显示歌曲总长ret = Left(ret, 8)If ret <> "" ThenProgressBar1.min = 0ProgressBar1.Max = Val(ret)Label3.Caption = Gettime(Val(ret))End Ifplay.Enabled = Falsepause.Enabled = Truestopplay.Enabled = Trueback.Enabled = Trueprew.Enabled = Truet = mciSendString("status " + mfn + " mode", ret, 128, 0)'得到设备的当前状态,是播放还是暂停等等ret = Left(ret, 8)StatusBar1.Panels(1).Text = ret'在状态栏显示播放状态t = mciSendString("play " + mfn + " form " + Str(ProgressBar1.V alue), 0&, 0, 0) '开始播放Timer1.Enabled = TrueEnd SubPrivate Sub pause_Click()t% = mciSendString("pause " + mfn, 0&, 0, 0)'发出暂停的命令play.Enable = Truepause.Enabled = Falsestopplay.Enabled = Trueback.Enabled = Falseprew.Enabled = FalseEnd SubPrivate Sub stopplay_Click()t% = mciSendString("stop " + mfn, 0&, 0, 0)t% = mciSendString("close " + mfn, 0&, 0, 0)'停止播放play.Enabled = Truepause.Enabled = Falsestopplay.Enabled = Falseback.Enabled = Falseprew.Enabled = FalseEnd SubPrivate Sub back_Click()t% = mciSendString("play " + mfn + " from " + Str(ProgressBar1.Value - (ProgressBar1.Max \ 10)), 0&, 0, 0) '向后跳一小段再播放End SubPrivate Sub prew_Click()t% = mciSendString("play " + mfn + " from " + Stri(ProgressBar1.Value + (ProgressBar1.Max \ 10)), 0&, 0, 0) '向前跳一小段再播放End SubPrivate Sub Timer1_Timer()Dim t As LongDim ret As String * 128t = mciSendString("status " + mfn + " position", ret, 0, 0)'得到当前播放位置ret = Left(ret, 8)ProgressBar1.Value = V al(ret)Label1.Caption = Gettime(Val(ret))'显示歌曲当前时间If ProgressBar1.Value = ProgressBar1.Max Thenstopplay_ClickEnd Ift = mciSendString("status " + mfn + " mode", ret, 128, 0)ret = Left(ret, 8)StatusBar1.Panels(1).Text = retEnd SubPrivate Sub Form_Unload(Cacel As Integer)t% = mciSendString("stop " + mfn, 0&, 0, 0)t% = mciSendString("close " + mfn, 0&, 0, 0)End SubPrivate Function Gettime(position As Long) As String'这个函数的功能是把以长整型表示的时间转换为电子钟式的"**:**"Dim min, secmin = position / 1000min = min / 60sec = min - Int(min)min = Int(min)sec = 60 * sec / 100sec = Int(sec * 100)Gettime = Str(min) + ":" + Str(sec)End Function。

音乐播放器(VB编程源代码)

音乐播放器(VB编程源代码)

音乐播放器设计一、先来欣赏一下本音乐播放器的最终效果吧:设计思路很简单,即下面两个窗体的设计。

二、主窗体(form1)界面设计如下:主窗体(form1)代码如下:Dim t As Integer, a As BooleanDim p As Integer, b, w As Boolean, onePrivate Sub allclear_Click()'清空播放列表List1.ClearWMP1.currentPlaylist.ClearForm1.Caption = "无任何曲目"End SubPrivate Sub allloop_Click()'全部循环播放Timer3.Enabled = Falseallloop.Checked = Trueoneloop.Checked = Falserand.Checked = Falserule.Checked = FalseCall WMP1.settings.setMode("loop", True)End SubPrivate Sub Form_Load()'初始化Form1.Height = 7800w = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Falserule.Checked = TrueLabel2.Caption = "00:00"'第一次打开时创建文件If Dir("filepath.text") = "" And Dir("C:\music.txt") = "" ThenOpen "C:\filepath.txt" For Output As #1Close #1Open "C:\music.txt" For Output As #2Close #2End If'读取文件Open "C:\filepath.txt" For Input As #1Open "C:\music.txt" For Input As #2Do While Not EOF(1)Input #1, XInput #2, YIf Dir(X) <> "" ThenList1.AddItem (List1.ListCount + 1) & "." & YCall WMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count, WMP1.newMedia(X)) End IfLoopClose #1Close #2'初始化If List1.ListCount <> 0 Then List1.Selected(0) = TruePicture3(0).Width = 114Picture3(0).Height = 52Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52Picture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52Picture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 0, 0, 19, 23a = FalseCall WMP1.settings.setMode("shuffle", False) '初始设置为顺序播放Label1.Caption = Mid(List1.List(0), InStr(List1.List(0), ".") + 1)sd1.Value = 50 '音量设置为50%End SubPrivate Sub List1_DblClick()'双击播放Call WMP1.Controls.playItem(WMP1.currentPlaylist.Item(List1.ListIndex))a = Truet = 1Picture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52End SubPrivate Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If X > List1.Width - 430 Thenw = TrueEnd IfEnd SubPrivate Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '伸缩播放列表If X > List1.Width - 430 And X < List1.Width - 330 ThenList1.MousePointer = 9ElseList1.MousePointer = 0End IfIf w = True And X > 1500 And X < 5800 ThenList1.Width = XEnd IfEnd SubPrivate Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)w = FalseEnd SubPrivate Sub List1_Scroll()List1.MousePointer = 0End SubPrivate Sub oneloop_Click()'单曲循环allloop.Checked = Falseoneloop.Checked = Truerand.Checked = Falserule.Checked = FalseTimer3.Enabled = TrueEnd SubPrivate Sub Pc13_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '播放进度控制If WMP1.playState = wmppsPlaying ThenWMP1.Controls.currentPosition = WMP1.currentMedia.duration * X / 233Pc13.ClsPc13.PaintPicture Pc14.Picture, 0, 0, 233, 17, 234 - X, 0, 233, 17End IfEnd SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '切换图片If t = 0 ThenPicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfIf t = 1 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfPicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52End SubPrivate Sub Picture10_Click()'打开搜索窗体Form2.ShowEnd SubPrivate Sub Picture11_Click()'设置静音sd1.Value = 0Picture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 38, 0, 19, 23End SubPrivate Sub Picture3_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)If Index = 0 ThenIf a = True ThenCall WMP1.Controls.pause '播放ElseCall WMP1.Controls.play '暂停End IfEnd IfIf Index = 3 Thenp = 1Call WMP1.Controls.Next '下一首p = 0End IfIf Index = 2 Thenp = 1Call WMP1.Controls.previous '上一首p = 0End IfIf Index = 4 Then Call WMP1.Controls.stop '停止播放'打开音乐文件If Index = 1 ThenCommonDialog1.DialogTitle = "打开音乐文件"CommonDialog1.Filter = "mp3|*.mp3|wma|*.wma"CommonDialog1.InitDir = "D:\"CommonDialog1.ShowOpenfname = CommonDialog1.FileTitlegname = CommonDialog1.FileNameIf fname <> "" Thenn = Len(fname)For i = 0 To List1.ListCount - 1If Right(List1.List(i), n - 4) = Left(fname, n - 4) ThenCall WMP1.Controls.playItem(WMP1.currentPlaylist.Item(i)) '播放添加后的歌曲Timer1.Enabled = TrueList1.ListIndex = iExit SubEnd IfNextList1.AddItem (List1.ListCount + 1) & "." & Left(fname, n - 4) '歌曲无重复则添加到播放列表,否则不再添加Call WMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count, WMP1.newMedia(gname))List1.ListIndex = List1.ListCount - 1List1.Selected(i) = TrueCall WMP1.Controls.playItem(WMP1.currentPlaylist.Item(List1.ListIndex))Timer1.Enabled = TrueEnd IfEnd IfEnd SubPrivate Sub Picture3_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)'根据不同情况切换图片,实现动态按钮功能If Index = 0 ThenIf t = 0 ThenIf X < 6 Or X > 80 Or Y < 6 Or Y > 48 ThenPicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52ElsePicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 228, 0, 114, 52End IfEnd IfIf t = 1 ThenIf X < 6 Or X > 80 Or Y < 6 Or Y > 48 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52ElsePicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 228, 0, 114, 52End IfEnd IfEnd IfIf Index = 1 ThenIf X < 6 Or X > 55 Or Y < 6 Or Y > 48 ThenPicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52ElsePicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 60, 0, 60, 52End IfEnd IfIf Index = 2 ThenIf X < 6 Or X > 65 Or Y < 6 Or Y > 48 ThenPicture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52ElsePicture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 83, 0, 83, 52End IfEnd IfIf Index = 3 ThenIf X < 6 Or X > 65 Or Y < 6 Or Y > 48 ThenPicture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52ElsePicture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 166, 0, 83, 52End IfEnd IfIf Index = 4 ThenIf X < 6 Or X > 55 Or Y < 6 Or Y > 48 ThenPicture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52ElsePicture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 120, 0, 60, 52End IfEnd IfEnd SubPrivate Sub Picture4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '图片切换'If t = 0 ThenPicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfIf t = 1 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfPicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52End SubPrivate Sub Picture5_Click()'显示或隐藏播放列表If b = 0 ThenForm1.Width = 5940Form1.Height = 3900b = 1Picture5.ToolTipText = "显示播放列表"ElseForm1.Width = 5940Form1.Height = 7800b = 0Picture5.ToolTipText = "隐藏播放列表"End IfEnd SubPrivate Sub Picture6_Click()'最小化窗体Form1.WindowState = 1End SubPrivate Sub Picture7_Click()'关闭窗体之前保存播放列表数据Open "C:\filepath.txt" For Output As #1Open "C:\music.txt" For Output As #2For i = 0 To List1.ListCount - 1n = InStr(List1.List(i), ".")Write #1, WMP1.currentPlaylist.Item(i).sourceURLWrite #2, Mid(List1.List(i), n + 1)NextClose #1Close #2EndEnd SubPrivate Sub Picture8_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) '播放模式设置菜单PopupMenu menusetEnd SubPrivate Sub Picture9_Click()'删除菜单PopupMenu gclearEnd SubPrivate Sub rand_Click()'随机播放Timer3.Enabled = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Truerule.Checked = FalseCall WMP1.settings.setMode("shuffle", True)End SubPrivate Sub rule_Click()'顺序播放Timer3.Enabled = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Falserule.Checked = TrueCall WMP1.settings.setMode("shuffle", False)End SubPrivate Sub sd1_Change()'音量控制条WMP1.settings.volume = sd1.Valuesd1.ToolTipText = "音量" & sd1.Value & "%'"If sd1.Value = 0 Then sd1.ToolTipText = "静音"If sd1.Value = 100 Then sd1.ToolTipText = "最大音量"If sd1.Value <> 0 ThenPicture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 0, 0, 19, 23End IfEnd SubPrivate Sub select_Click()'删除选中项For i = 0 To List1.ListCount - 1If List1.Selected(i) ThenList1.RemoveItem (i)m = iCall WMP1.currentPlaylist.RemoveItem(WMP1.currentPlaylist.Item(i)) Exit ForEnd IfNextFor i = 0 To List1.ListCount - 1n = InStr(List1.List(i), ".")List1.List(i) = (i + 1) & "." & Mid(List1.List(i), n + 1)NextIf List1.ListCount = 0 Then Exit SubIf List1.ListCount = m ThenList1.Selected(m - 1) = TrueElseList1.Selected(m) = TrueEnd IfEnd SubPrivate Sub Timer1_Timer()'更新播放动态If WMP1.currentPlaylist.Count <> 0 ThenIf WMP1.playState = 3 ThenLabel2.Caption = WMP1.Controls.currentPositionStringPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52a = Truet = 1Picture3(0).ToolTipText = "播放"ElseLabel2.Caption = "00:00"Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52a = Falset = 0Picture3(0).ToolTipText = "暂停"End IfEnd IfIf WMP1.playState = 2 ThenLabel2.Caption = WMP1.Controls.currentPositionString '显示播放进度(时间)End IfPc13.ClsIf WMP1.playState = 3 Or WMP1.playState = 2 ThenPc13.PaintPicture Pc14.Picture, 0, 0, 233, 17, 234 - 233 * WMP1.Controls.currentPosition / WMP1.currentMedia.duration, 0, 233, 17End IfEnd SubPrivate Sub Timer2_Timer()'标题动态显示If WMP1.currentPlaylist.Count <> 0 ThenIf WMP1.playState <> 3 ThenForm1.Caption = "暂停播放——" + WMP1.currentMedia.getItemInfo("title")ElseForm1.Caption = "正在播放——" + WMP1.currentMedia.getItemInfo("title")End IfEnd IfEnd SubPrivate Sub Timer3_Timer()'单曲循环If WMP1.currentMedia.duration - 0.5 < WMP1.Controls.currentPosition ThenCall WMP1.Controls.playItem(WMP1.currentPlaylist.Item(one))End IfEnd SubPrivate Sub WMP1_OpenStateChange(ByVal NewState As Long)n = 0If p = 0 ThenFor i = 0 To List1.ListCount - 1If WMP1.currentPlaylist.Item(i).getItemInfo("title") <> WMP1.currentMedia.getItemInfo("title") Thenn = n + 1ElseExit ForEnd IfNextone = nLabel1.Caption = Mid(List1.List(n), InStr(List1.List(n), ".") + 1) '显示正在播放的曲目List1.Selected(n) = TrueEnd IfLabel3.Caption = WMP1.currentMedia.durationString '显示歌曲总长End Sub三、副窗体(form1)界面设计如下:说明:该窗体用于搜索电脑已有歌曲(本音乐播放器的特色所在)副窗体(form1)代码如下:Dim n As Integer, temp(10000) As String, m As IntegerPrivate Sub choose_Click()'选择全部歌曲For i = 0 To List2.ListCount - 1List2.Selected(i) = TrueNext iEnd SubPrivate Sub choosenone_Click()'清除选择For i = 0 To List2.ListCount - 1List2.Selected(i) = FalseNext iEnd SubPrivate Sub Command1_Click()'搜索歌曲并保存Open "C:\searchresult.txt" For Output As #1Open "C:\geresult.txt" For Output As #2List2.ClearDim s As StringCall find(Combo1.Text)If m = n Then s = MsgBox("搜索完毕", vbInformation, "提示")Close #1Close #2End SubPrivate Sub Command2_Click()'将选中歌曲添加到播放列表For i = 0 To List2.ListCount - 1t = 0If List2.Selected(i) = True ThenFor j = 0 To Form1.List1.ListCount - 1n = Len(List2.List(i))If Right(Form1.List1.List(j), n) = List2.List(i) Then t = t + 1: Exit ForNextIf t = 0 ThenForm1.List1.AddItem (Form1.List1.ListCount + 1) & "." & List2.List(i)Call Form1.WMP1.currentPlaylist.insertItem(Form1.WMP1.currentPlaylist.Count, Form1.WMP1.newMedia(List3.List(i)))End IfEnd IfNext iFor i = 1 To List2.SelCountFor j = 0 To List2.ListCount - 1If List2.Selected(j) ThenList2.RemoveItem jList3.RemoveItem jExit ForEnd IfNext jNext is = MsgBox("已添加到播放列表", vbInformation, "提示")End SubPrivate Sub Command3_Click()'读取文件(上次最后一次搜索结果)If Dir("C:\searchresult.txt") <> "" And Dir("C:\geresult.txt") <> "" ThenOpen "C:\searchresult.txt" For Input As #1Open "C:\geresult.txt" For Input As #2Do While Not EOF(1)Input #1, XInput #2, YList3.AddItem XList2.AddItem YLoopClose #1Close #2s = MsgBox("上次搜索结果读取完成!", vbInformation, "提示")Elses = MsgBox("没有任何搜索记录!", vbInformation, "提示")End IfEnd SubPrivate Sub Form_Load()'选择搜索条件即路径和文件格式Combo1.Text = Combo1.List(0)Combo2.Text = Combo2.List(0)Form2.Picture = LoadPicture("")End SubPrivate Function find1() '文件搜索函数Dim i As StringDim a As Integer, b As Integera = m:b = nDim k As IntegerFor k = a To bIf temp(k) = "" Then Exit Functionfind (temp(k))NextEnd Function'*************************************'获取该路径下的文件,并且存储目录文件的路径******************************************Private Function find(ByVal path As String) '文件搜索函数Dim i As Stringm = ni = Dir(path, vbDirectory)Do While i <> ""If i <> "." And i <> ".." ThenIf (GetAttr(path & i) And vbDirectory) <> 0 Thentemp(n) = path & i & "\"n = n + 1ElseDoEventsIf Right(i, Len(Combo2.Text)) = Combo2.Text ThenList3.AddItem path & iWrite #1, path & iWrite #2, Left(i, Len(i) - 4)List2.AddItem Left(i, Len(i) - 4)End IfEnd IfEnd Ifi = DirLoopfind1End Function总结:本音乐播放器的界面还可以设计的更加漂亮好看,这个就得发挥你的界面设计能力咯!以上播放器的设计还有很多可以改善的地方,比如代码能否更加简化?还缺少哪些功能?如何更加赏心悦目?这些就交给你自己去完善咯!另外,为了方便有兴趣的人更好的理解整个设计过程,我已共享该音乐播放器程序设计的整个工程文件(本程序用到的图片也含有)到以下网址:可以下载看看,希望对你有所帮助!。

用VB制作mp3播放器

用VB制作mp3播放器
mciSendString "close movie",0&,0,0
七、开关光驱:
mciSendString "set cdaudio door open", "", 0, 0 '打开
mciSendString "set cdaudio door close", "", 0, 0 '关闭
Style %u 样式
notify 通知
2.播放(Play),格式:Play 设备名 [from 起点][to 终点]
mciSendString "play movie", 0&, 0, 0
mciSendString "play movie fullscreen", 0&, 0, 0 '全屏播放
一、常用命令
1.打开(Open),格式:Open 设备名 [type 设备型式][alias 别名]
Dim mName as string
mName = "f:\\mpeg\\mpeg1.avi"
mciSendString "open mName type MPEGVideo Alias movie parent %u Style %u notify",0&, 0, 0
(调用mciSendString第一个参数传“play 文件全路径”就可以,“文件全路径”最好传绝对路径,不建议wanghepeng10那样值传递文件名。
另外如果文件全路径中含有空格的话要使用GetShortPathName转换成短路径。)
11. 获取媒体的总长度:
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

媒体播放器很多,但是定制的广告令人生厌,还是自己动手做一个和WindowsMediaPlayer 播放器效果一样的吧,直接用微软提供的WindowsMediaPlayer 控件就可以,下边简单介绍一下WindowsMediaPlayer 控件的用法。

这里用VB 开发,用VC 任然是一样的,只不过VC 中进行类操作,属性和方法的使用是完全一样,下边只列出部分功能,以起抛砖引玉的作用。

有兴趣的朋友可以继续完善哦!
制作步骤:
一、控件添加
这是必须的,VB 中在工具箱中点击右键添加,选中WindowsMediaPlayer ,然后工具箱中会出现一个我们非常熟悉的WindowsMediaPlayer 图标。

二、界面
在工具箱里添加WindowsMediaPlayer 控件,然后新建一个窗体,将WindowsMediaPlayer 控件加进去,可以用控件按钮(打开、播放、暂停、停止等),也可以自己设计(如本文中)。

三、添加代码如下
Dim flag As Boolean
Private Sub Form_Load(
With WindowsMediaPlayer1
.uiMode = "full"
End With
End Sub
' 播放暂停
Private Sub Command1_Click( flag = Not flag
With WindowsMediaPlayer1 If flag = True Then Command1.Caption = "pause" .Controls.Play
Else
Command1.Caption = "play" .Controls.pause
End If
End With
End Sub
' 停止
Private Sub Command2_Click( With WindowsMediaPlayer1 .Controls.Stop
End With
End Sub
Private Sub Command4_Click( '打开文件
With CommonDialog1
' .Filter = "avi (*.avi|*.avi"
.ShowOpen
End With
With WindowsMediaPlayer1
' .URL = App.Path + "\017 喜欢你没道理张韶涵.mp3"
.Controls.Stop
End With
' 快进
Private Sub Command3_Click(
With WindowsMediaPlayer1
.Controls.currentPosition = .Controls.currentPosition + 10
End With
End Sub
' 快退
Private Sub Command5_Click(
With WindowsMediaPlayer1
.Controls.currentPosition = .Controls.currentPosition - 10 End With
End Sub。

相关文档
最新文档