扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:刘 涛 来源:yesky 2007年10月15日
关键字:
Option Explicit Private m_dblRate As Double '多媒体流播放的幀速率,也既是每秒播放的幀数; Private m_bstrFileName As String '需要播放的流媒体文件名; Private m_dblRunLength As Double '播放的流媒体的持续时间,单位为秒; Private m_dblStartPosition As Double '待播放的流媒体文件的初始位置,以秒为单位; Private m_boolVideoRunning As Boolean '多媒体流正在播放的标志; Private m_objBasicAudio As IBasicAudio 'Basic 的音频对象,用来处理媒体流中的语音数据; Private m_objVideoWindow As IVideoWindow '视频窗口对象; Private m_objFilgraphManager As FilgraphManager '媒体控制对象; Private m_objMediaPosition As IMediaPosition '媒体位置对象; |
Private Sub Form_Load() On Local Error GoTo ErrLine optPlaybackRate(1).Value = True '回放速率设置为正常; frmMain.ScaleMode = 3 '窗体的坐标单位设置为像素; '将工具栏上的所有按钮设置为"无效" tbControlBar.Buttons("play").Enabled = False tbControlBar.Buttons("stop").Enabled = False tbControlBar.Buttons("pause").Enabled = False Exit Sub ErrLine: Err.Clear Exit Sub End Sub |
Private Sub Form_Unload(Cancel As Integer) On Local Error GoTo ErrLine '停止播放; m_boolVideoRunning = False DoEvents If m_objFilgraphManager <>NULL Then m_objFilgraphManager.Stop End If '清除视频窗口; If m_objVideoWindow <> NULL Then m_objVideoWindow.Owner = 0 '设置m_objVideoWindow对象的拥有者为空; End If '清除与多媒体流相关的全局对象; If m_objBasicAudio <> Null Then Set m_objBasicAudio = Nothing If m_objBasicVideo <> NULL Then Set m_objBasicVideo = Nothing If m_objFilgraphManager <> NULL Then Set m_objFilgraphManager = Nothing If m_objVideoWindow <> NULL Then Set m_objVideoWindow = Nothing If m_objMediaPosition <> NULL Then Set m_objMediaPosition = Nothing Exit Sub ErrLine: Err.Clear Exit Sub End Sub |
Private Sub mnu_FileExit_Click() Dim frm As Form On Local Error GoTo ErrLine For Each frm In Forms frm.Move Screen.Width * 8, Screen.Height * 8 frm.Visible = False: Unload frm Next Exit Sub ErrLine: Err.Clear Exit Sub End Sub |
Private Sub mnu_FileOpen_Click() Dim nCount As Long On Local Error GoTo ErrLine '清理内存,防止在此之前已经打开过一个文件; Call Form_Unload(True) '选择打开的文件类型默认为:mov、avi、mp3、mp2、wav; ctrlCommonDialog.Filter="MediaFiles (*.mpg;*.avi;*.mov;*.wav;*.mp2;*.mp3)|*.mpg;*.avi;*.mov;*.wav;*.mp2;*.mp3" ctrlCommonDialog.ShowOpen m_bstrFileName = ctrlCommonDialog.FileName '初始化一个滤波器图表 Set m_objFilgraphManager = New FilgraphManager Call m_objFilgraphManager.RenderFile(m_bstrFileName) '装载流媒体文件; '设置Basic的音频对象,如语音的大小、平衡度等; Set m_objBasicAudio = m_objFilgraphManager m_objBasicAudio.Volume = slVolume.Value m_objBasicAudio.Balance = slBalance.Value '设置视频窗口对象,初始化位置后将其父窗口设置为窗口上的PictureBox对象; Set m_objVideoWindow = m_objFilgraphManager m_objVideoWindow.WindowStyle = CLng(&H6000000) m_objVideoWindow.Top = 0 m_objVideoWindow.Left = 0 m_objVideoWindow.Width = picVideoWindow.Width m_objVideoWindow.Height = picVideoWindow.Height m_objVideoWindow.Owner = picVideoWindow.hWnd '设置多媒体位置对象; Set m_objMediaPosition = m_objFilgraphManager '根据用户的选择来设置多媒体流的播放速率; For nCount = optPlaybackRate.LBound To optPlaybackRate.UBound If optPlaybackRate(nCount).Value = True Then Select Case nCount Case 0 If m_objMediaPosition <>NULL Then _ m_objMediaPosition.Rate = 0.5 Case 1 If m_objMediaPosition <>NULL Then _ m_objMediaPosition.Rate = 1 Case 2 If m_objMediaPosition <> NULL Then _ m_objMediaPosition.Rate = 2 End Select Exit For End If Next m_dblRunLength = Round(m_objMediaPosition.Duration, 2) txtDuration.Text = CStr(m_dblRunLength) ' 设置当前位置为起始位置; m_dblStartPosition = 0 ' 显示用户选择的多媒体流的播放速率; m_dblRate = m_objMediaPosition.Rate txtRate.Text = CStr(m_dblRate) '设置按钮的默认状态; tbControlBar.Buttons("play").Enabled = True tbControlBar.Buttons("stop").Enabled = False tbControlBar.Buttons("pause").Enabled = False Call tbControlBar_ButtonClick(tbControlBar.Buttons(1)) ErrLine: Err.Clear Resume Next Exit Sub End Sub |
Private Sub optPlaybackRate_Click(Index As Integer) On Local Error GoTo ErrLine Select Case Index Case 0 If m_objMediaPosition<> NULL Then _ txtRate.Text = 0.5 Case 1 If m_objMediaPosition<> NULL Then _ txtRate.Text = 1 Case 2 If m_objMediaPosition<> NULL Then _ txtRate.Text = 2 End Select '重新设置媒体回放的播放速率; If m_objMediaPosition Then Select Case Index Case 0 If m_objMediaPosition <>NULL Then _ m_objMediaPosition.Rate = 0.5 Case 1 If m_objMediaPosition <> NULL Then _ m_objMediaPosition.Rate = 1 Case 2 If m_objMediaPosition <> NULL Then _ m_objMediaPosition.Rate = 2 End Select End If Exit Sub ErrLine: Err.Clear Exit Sub End Sub |
Private Sub slBalance_Change() On Local Error GoTo ErrLine '用户使用滑动条来设置语音平衡的值; If m_objFilgraphManager <> NULL Then _ m_objBasicAudio.Balance = slBalance.Value Exit Sub ErrLine: Err.Clear Exit Sub End Sub |
Private Sub slVolume_Change() On Local Error GoTo ErrLine '用户使用滑动条来设置语音的大小; If m_objFilgraphManager <>NULL Then _ m_objBasicAudio.Volume = slVolume.Value Exit Sub ErrLine: Err.Clear Exit Sub End Sub |
Private Sub tbControlBar_ButtonClick(ByVal Button As Button) On Local Error GoTo ErrLine If ObjPtr(m_objMediaControl) > 0 Then If Button.Key = "play" Then '如果用户点击了"播放"按钮; '如果多媒体的当前位置不处在文件尾部,则对多媒体流的位置重新置位; If CLng(m_objMediaPosition.CurrentPosition) < CLng(m_dblStartPosition) Then m_objMediaPosition.CurrentPosition = m_dblStartPosition ElseIf CLng(m_objMediaPosition.CurrentPosition) = CLng(m_dblRunLength) Then m_objMediaPosition.CurrentPosition = m_dblStartPosition End If Call m_objFilgraphManager.Run m_boolVideoRunning = True tbControlBar.Buttons("play").Enabled = False tbControlBar.Buttons("stop").Enabled = True tbControlBar.Buttons("pause").Enabled = True picVideoWindow.Refresh ElseIf Button.Key = "pause" Then '用户点击了"暂停"按钮; Call m_objFilgraphManager.Pause m_boolVideoRunning = False tbControlBar.Buttons("play").Enabled = True tbControlBar.Buttons("stop").Enabled = True tbControlBar.Buttons("pause").Enabled = False ElseIf Button.Key = "stop" Then '用户点击了"停止"按钮; Call m_objFilgraphManager.Stop m_boolVideoRunning = False ' 重新设置视频流的当前播放位置为起始位置; m_objMediaPosition.CurrentPosition = 0 txtElapsed.Text = "0.0" tbControlBar.Buttons("play").Enabled = True tbControlBar.Buttons("stop").Enabled = False tbControlBar.Buttons("pause").Enabled = False End If End If Exit Sub ErrLine: Err.Clear Exit Sub End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者