首页/技术开发/内容

VB中用Multimedia MCI控件开发多媒体应用

技术开发2024-01-08 阅读()
*.avi″
  CommonDialog1.ShowOpen
  MMControl1.Notify = False
  MMControl1.Wait = True
  MMControl1.Shareable = False
  ′由系统默认设备类型
  MMControl1.DeviceType = ″″
  MMControl1.filename = CommonDialog1.filename
  ′ 打开 MCI 设备。
  MMControl1.Command = ″Open″
  MnuClose.Enabled = True
  Slider1.Visible = True
  End Sub
  Private Sub MMControl1_StatusUpdate()
  On Error GoTo Erropen
  ′设置文件长度以毫秒形式返回,
  MMControl1.TimeFormat = 0
  Slider1.Max = MMControl1.Length / 1000
  If MMControl1.Position <> MMControl1.Length Then
  Slider1.Value = MMControl1.Position / 1000
  Else
  MMControl1.Command = ″Prev″
  Slider1.Value = 0
  End If
  ′调用Tstring函数计算剩余时间和总时间
  StatusBar1.Panels(2) = Tstring(MMControl1.Length - MMControl1.Position)
  StatusBar1.Panels(4) = Tstring(MMControl1.Length)
  Label1.Caption = ″00:00″
  Label2.Caption = Tstring(MMControl1.Length / 2)
  Label3.Caption = Tstring(MMControl1.Length)
  ′ 由Mode返回不同值并在状态栏经出相应的提示
  Select Case MMControl1.Mode
  Case 524
  StatusBar1.Panels(5) = ″ 未打开设备……″
  Case 525
  StatusBar1.Panels(5) = ″停止状态……″
  Case 526
  StatusBar1.Panels(5) = ″正在播放……″ & CommonDialog1.FileTitle
  Case 527
  StatusBar1.Panels(5) = ″正在录音……″
  Case 528
  StatusBar1.Panels(5) = ″正在搜索……″
  Case 529
  StatusBar1.Panels(5) = ″暂停播放……″
  Case 530
  StatusBar1.Panels(5) = ″设备就绪……″
  End Select
  Erropen:
  ′ 放弃打开文件
  End Sub
  ′ 自定义将毫秒转化为分、秒Tstring函数
  Private Function Tstring(sm As Long) As String
  s = (sm / 1000 / 60) Mod 60
  m = (sm / 1000) Mod 60
  Tstring = Format(s, ″00″) & ″;″ & Format(m, ″00″)
  End Function
  Private Sub MMControl1_Done(NotifyCode As Integer)
  MMControl1.UpdateInterval = 100 ′ 间隔100毫秒
  End Sub
  Private Sub MnuClose_Click()
  MMControl1.Command = ″Close″
  MnuClose.Enabled = False
  End Sub
  Private Sub MnuExit_Click()
  MMControl1.Command = ″Close″
  End
  End Sub
  Private Sub Check1_Click()
  If Check1.Value = 1 Then
  MMControl1.Command = ″Play″ ′ 继续播放
  End If
  End Sub
  此外,欲在当前窗口播放*.avi文件,可在窗体加一个PictureBox,在Private Sub MMControl1_StatusUpdate()中加入MMControl1.hWndDisplay = Picture1.hWnd一句。运行时如图2。
(本程序在VB5.0,PⅡ350中通过)

第1页  第2页  第3页  第4页  第5页  第6页 

……

相关阅读