AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > VB编程

利用Visual Basic设计多媒体应用程序

51自学网 http://www.wanshiok.com



五、Visual Basic多媒体应用程序设计实例
   1、播放CD音乐
   在很多多媒体软件系统中,都提供了激光唱盘的播放软件,利用多媒体控件MCI.OCX,我们可以轻松地编制出符合自己使用要求的简易激光唱盘播放机。
   表1给出了简易CD播放器的主要控制部件定义,其后是对应于各个触发事件的源程序代码。
完整的源程序清单如下:
   'CD播放机实用程序
   '运行程序前请在CD-ROM驱动器中装入一张激光唱碟'“LOAD”按钮触发事件
   Private Sub Command1_Click()
   '装入CD唱片
   On Error GoTo MCI_ERROR
   MMControl1.Command = "Open"
   On Error GoTo 0
   '设置时间格式
   MMControl1.TimeFormat = vbMCIFormatTmsf
   '关闭LOAD按钮,显示图片
   Command1.Enabled = False
   Picture1.Picture = Picture3.Picture
   ' 设置初始轨道数
   Label1.Caption = "1"
   Exit Sub
   MCI_ERROR:
   DisplayErrorMessageBox
   Resume MCI_EXIT
   MCI_EXIT:
   Unload CD
   End Sub

   Private Sub Form_Load()
   MMControl1.Wait = True
   MMControl1.UpdateInterval = 0
   ' 设置设备类型
   MMControl1.DeviceType = "CDAudio"
   '设置缺省轨道数为0
   Label1.Caption = "0"
   End Sub

   Private Sub Form_Unload(Cancel As Integer)
   MCITest.Show
   End Sub

   '“出带”按钮触发事件
   Private Sub MMControl1_EjectClick(Cancel As Integer)
   Command1.Enabled = True
   Picture1.Picture = Picture2.Picture
   MMControl1.UpdateInterval = 0
   On Error GoTo MCI_ERROR2
   MMControl1.Command = "Eject"
   MMControl1.Command = "Close"
   On Error GoTo 0
   Label1.Caption = "0"
   Label3.BackColor = &H404040
   Exit Sub
   MCI_ERROR2:
   DisplayErrorMessageBox
   Resume Next
   End Sub

   '“向前”按钮触发事件
   Private Sub MMControl1_NextCompleted(ErrorCode As Long)
   Label1.Caption = Str$(MMControl1.Track)
   End Sub

   '“暂停”按钮触发事件
   Private Sub MMControl1_PauseClick(Cancel As Integer)
   MMControl1.UpdateInterval = 0
   Label3.BackColor = &H404040
   End Sub

   '“播放”按钮触发事件
   Private Sub MMControl1_PlayClick(Cancel As Integer)
   MMControl1.UpdateInterval = 1000
   Label1.Caption = Str$(MMControl1.Track)
   End Sub

   '“向后”按钮触发事件
   Private Sub MMControl1_PrevCompleted(ErrorCode As Long)
   Label1.Caption = Str$(MMControl1.Track)
   End Sub

   Private Sub MMControl1_StatusUpdate()
   Label1.Caption = Str$(MMControl1.Position And &HFF)
   If MMControl1.Mode = vbMCIModePlay Then
   Label3.BackColor = &H80FF&
   Else
   Label3.BackColor = &H404040
   End If
   End Sub

   '“停止”按钮触发事件
   Private Sub MMControl1_StopClick(Cancel As Integer)
   MMControl1.UpdateInterval = 0
   Label3.BackColor = &H404040
   MMControl1.To = MMControl1.Start
   MMControl1.Command = "Seek"
   MMControl1.Track = 1
   Label1.Caption = "1"
   End Sub

 
 

上一篇:电影结束画面的卷动效果  下一篇:在VB5中如何使机箱内的小喇叭发出不同的声音?