home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8vbsdk.exe / samples / multimedia / vbsamples / directshow / vbdemo / vbdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-10-11  |  32.0 KB  |  786 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form frmMain 
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "DirectShow VB Sample"
  7.    ClientHeight    =   8190
  8.    ClientLeft      =   75
  9.    ClientTop       =   600
  10.    ClientWidth     =   5625
  11.    DrawMode        =   1  'Blackness
  12.    DrawStyle       =   5  'Transparent
  13.    HasDC           =   0   'False
  14.    Icon            =   "vbdemo.frx":0000
  15.    LinkTopic       =   "frmMain"
  16.    LockControls    =   -1  'True
  17.    MaxButton       =   0   'False
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   8190
  20.    ScaleWidth      =   5625
  21.    Begin MSComctlLib.Toolbar tbControlBar 
  22.       Align           =   1  'Align Top
  23.       Height          =   540
  24.       Left            =   0
  25.       TabIndex        =   20
  26.       Top             =   0
  27.       Width           =   5625
  28.       _ExtentX        =   9922
  29.       _ExtentY        =   953
  30.       ButtonWidth     =   820
  31.       ButtonHeight    =   794
  32.       Appearance      =   1
  33.       ImageList       =   "ctrlImageList"
  34.       _Version        =   393216
  35.       BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
  36.          NumButtons      =   3
  37.          BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  38.             Key             =   "play"
  39.             Object.ToolTipText     =   "Play"
  40.             ImageIndex      =   1
  41.          EndProperty
  42.          BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  43.             Key             =   "pause"
  44.             Object.ToolTipText     =   "Pause"
  45.             ImageIndex      =   2
  46.          EndProperty
  47.          BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  48.             Key             =   "stop"
  49.             Object.ToolTipText     =   "Stop"
  50.             ImageIndex      =   3
  51.          EndProperty
  52.       EndProperty
  53.    End
  54.    Begin VB.PictureBox picVideoWindow 
  55.       BackColor       =   &H00000000&
  56.       ClipControls    =   0   'False
  57.       DrawMode        =   1  'Blackness
  58.       DrawStyle       =   5  'Transparent
  59.       HasDC           =   0   'False
  60.       Height          =   4095
  61.       Left            =   60
  62.       ScaleHeight     =   4035
  63.       ScaleWidth      =   5415
  64.       TabIndex        =   16
  65.       Top             =   660
  66.       Width           =   5475
  67.    End
  68.    Begin VB.Frame fraInfo 
  69.       Caption         =   "Information:"
  70.       Height          =   2055
  71.       Left            =   60
  72.       TabIndex        =   9
  73.       Top             =   6060
  74.       Width           =   5475
  75.       Begin VB.OptionButton optPlaybackRate 
  76.          Caption         =   "Double (200%)"
  77.          Height          =   195
  78.          Index           =   2
  79.          Left            =   3900
  80.          TabIndex        =   2
  81.          ToolTipText     =   "Double Speed"
  82.          Top             =   1680
  83.          Width           =   1335
  84.       End
  85.       Begin VB.OptionButton optPlaybackRate 
  86.          Caption         =   "Normal (100%)"
  87.          Height          =   195
  88.          Index           =   1
  89.          Left            =   2460
  90.          TabIndex        =   1
  91.          ToolTipText     =   "Normal Speed"
  92.          Top             =   1680
  93.          Width           =   1515
  94.       End
  95.       Begin VB.OptionButton optPlaybackRate 
  96.          Caption         =   "Half (50%)"
  97.          Height          =   195
  98.          Index           =   0
  99.          Left            =   1320
  100.          TabIndex        =   0
  101.          ToolTipText     =   "Half Speed"
  102.          Top             =   1680
  103.          Width           =   1215
  104.       End
  105.       Begin VB.TextBox txtDuration 
  106.          BackColor       =   &H8000000F&
  107.          ForeColor       =   &H80000012&
  108.          Height          =   270
  109.          Left            =   1920
  110.          Locked          =   -1  'True
  111.          TabIndex        =   12
  112.          TabStop         =   0   'False
  113.          Top             =   360
  114.          Width           =   3315
  115.       End
  116.       Begin VB.TextBox txtElapsed 
  117.          BackColor       =   &H8000000F&
  118.          ForeColor       =   &H80000012&
  119.          Height          =   270
  120.          Left            =   1920
  121.          Locked          =   -1  'True
  122.          TabIndex        =   11
  123.          TabStop         =   0   'False
  124.          Top             =   720
  125.          Width           =   3315
  126.       End
  127.       Begin VB.TextBox txtRate 
  128.          BackColor       =   &H8000000F&
  129.          ForeColor       =   &H80000012&
  130.          Height          =   270
  131.          Left            =   1920
  132.          Locked          =   -1  'True
  133.          TabIndex        =   10
  134.          TabStop         =   0   'False
  135.          Top             =   1080
  136.          Width           =   3315
  137.       End
  138.       Begin VB.Label lblResetSpeed 
  139.          Caption         =   "Reset speed:"
  140.          Height          =   255
  141.          Left            =   240
  142.          TabIndex        =   17
  143.          Top             =   1680
  144.          Width           =   1095
  145.       End
  146.       Begin VB.Line Line1 
  147.          X1              =   240
  148.          X2              =   5240
  149.          Y1              =   1500
  150.          Y2              =   1500
  151.       End
  152.       Begin VB.Label lblElapsed 
  153.          Caption         =   "Elapsed Time:"
  154.          Height          =   255
  155.          Left            =   240
  156.          TabIndex        =   15
  157.          ToolTipText     =   "Elapsed Time (Seconds)"
  158.          Top             =   720
  159.          Width           =   1575
  160.       End
  161.       Begin VB.Label lblRate 
  162.          Caption         =   "Playback speed:"
  163.          Height          =   255
  164.          Left            =   240
  165.          TabIndex        =   14
  166.          ToolTipText     =   "Playback Speed (Frames Per Second)"
  167.          Top             =   1080
  168.          Width           =   1335
  169.       End
  170.       Begin VB.Label lblDuration 
  171.          Caption         =   "Length:"
  172.          Height          =   255
  173.          Left            =   240
  174.          TabIndex        =   13
  175.          ToolTipText     =   "Media Length (Seconds)"
  176.          Top             =   360
  177.          Width           =   1455
  178.       End
  179.    End
  180.    Begin VB.Frame frameBalance 
  181.       Caption         =   "Balance"
  182.       Height          =   1215
  183.       Left            =   2820
  184.       TabIndex        =   6
  185.       Top             =   4800
  186.       Width           =   2715
  187.       Begin MSComctlLib.Slider slBalance 
  188.          Height          =   495
  189.          Left            =   340
  190.          TabIndex        =   19
  191.          Top             =   300
  192.          Width           =   2000
  193.          _ExtentX        =   3519
  194.          _ExtentY        =   873
  195.          _Version        =   393216
  196.          LargeChange     =   1000
  197.          SmallChange     =   500
  198.          Min             =   -5000
  199.          Max             =   5000
  200.          TickFrequency   =   1000
  201.       End
  202.       Begin VB.Label lblRight 
  203.          Caption         =   "Right"
  204.          Height          =   255
  205.          Left            =   2160
  206.          TabIndex        =   8
  207.          Top             =   840
  208.          Width           =   435
  209.       End
  210.       Begin VB.Label lblLeft 
  211.          Caption         =   "Left"
  212.          Height          =   255
  213.          Left            =   120
  214.          TabIndex        =   7
  215.          Top             =   840
  216.          Width           =   495
  217.       End
  218.    End
  219.    Begin VB.Timer tmrTimer 
  220.       Left            =   1080
  221.       Top             =   8640
  222.    End
  223.    Begin VB.Frame frameVolume 
  224.       Caption         =   "Volume"
  225.       Height          =   1215
  226.       Left            =   60
  227.       TabIndex        =   3
  228.       Top             =   4800
  229.       Width           =   2595
  230.       Begin MSComctlLib.Slider slVolume 
  231.          Height          =   495
  232.          Left            =   340
  233.          TabIndex        =   18
  234.          Top             =   300
  235.          Width           =   2000
  236.          _ExtentX        =   3519
  237.          _ExtentY        =   873
  238.          _Version        =   393216
  239.          LargeChange     =   1000
  240.          SmallChange     =   500
  241.          Min             =   -10000
  242.          Max             =   0
  243.          TickFrequency   =   1000
  244.       End
  245.       Begin VB.Label lblMax 
  246.          Caption         =   "Max"
  247.          Height          =   255
  248.          Left            =   2100
  249.          TabIndex        =   5
  250.          Top             =   840
  251.          Width           =   375
  252.       End
  253.       Begin VB.Label lblMin 
  254.          Caption         =   "Min"
  255.          Height          =   255
  256.          Left            =   120
  257.          TabIndex        =   4
  258.          Top             =   840
  259.          Width           =   495
  260.       End
  261.    End
  262.    Begin MSComDlg.CommonDialog ctrlCommonDialog 
  263.       Left            =   600
  264.       Top             =   8580
  265.       _ExtentX        =   847
  266.       _ExtentY        =   847
  267.       _Version        =   393216
  268.    End
  269.    Begin MSComctlLib.ImageList ctrlImageList 
  270.       Left            =   0
  271.       Top             =   8580
  272.       _ExtentX        =   1005
  273.       _ExtentY        =   1005
  274.       BackColor       =   -2147483643
  275.       ImageWidth      =   24
  276.       ImageHeight     =   24
  277.       MaskColor       =   12632256
  278.       _Version        =   393216
  279.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  280.          NumListImages   =   3
  281.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  282.             Picture         =   "vbdemo.frx":0442
  283.             Key             =   ""
  284.          EndProperty
  285.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  286.             Picture         =   "vbdemo.frx":0554
  287.             Key             =   ""
  288.          EndProperty
  289.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  290.             Picture         =   "vbdemo.frx":0666
  291.             Key             =   ""
  292.          EndProperty
  293.       EndProperty
  294.    End
  295.    Begin VB.Menu mnu_File 
  296.       Caption         =   "&File"
  297.       Begin VB.Menu mnu_FileOpen 
  298.          Caption         =   "&Open"
  299.          Shortcut        =   ^O
  300.       End
  301.       Begin VB.Menu mnuFileSeptum 
  302.          Caption         =   "-"
  303.       End
  304.       Begin VB.Menu mnu_FileExit 
  305.          Caption         =   "E&xit"
  306.       End
  307.    End
  308. Attribute VB_Name = "frmMain"
  309. Attribute VB_GlobalNameSpace = False
  310. Attribute VB_Creatable = False
  311. Attribute VB_PredeclaredId = True
  312. Attribute VB_Exposed = False
  313. '*******************************************************************************
  314. '*       This is a part of the Microsoft DXSDK Code Samples.
  315. '*       Copyright (C) 1999-2000 Microsoft Corporation.
  316. '*       All rights reserved.
  317. '*       This source code is only intended as a supplement to
  318. '*       Microsoft Development Tools and/or SDK documentation.
  319. '*       See these sources for detailed information regarding the
  320. '*       Microsoft samples programs.
  321. '*******************************************************************************
  322. Option Explicit
  323. Option Base 0
  324. Option Compare Text
  325. Private m_dblRate As Double                          'Rate in Frames Per Second
  326. Private m_bstrFileName As String                   'Loaded Filename
  327. Private m_dblRunLength As Double                'Duration in seconds
  328. Private m_dblStartPosition As Double             'Start position in seconds
  329. Private m_boolVideoRunning As Boolean       'Flag used to trigger clock
  330. Private m_objBasicAudio  As IBasicAudio         'Basic Audio Object
  331. Private m_objBasicVideo As IBasicVideo          'Basic Video Object
  332. Private m_objMediaEvent As IMediaEvent        'MediaEvent Object
  333. Private m_objVideoWindow As IVideoWindow   'VideoWindow Object
  334. Private m_objMediaControl As IMediaControl    'MediaControl Object
  335. Private m_objMediaPosition As IMediaPosition 'MediaPosition Object
  336. ' **************************************************************************************************************************************
  337. ' * PRIVATE INTERFACE- FORM EVENT HANDLERS
  338.             ' ******************************************************************************************************************************
  339.             ' * procedure name: Form_Load
  340.             ' * procedure description:  Occurs when a form is loaded.
  341.             ' *
  342.             ' ******************************************************************************************************************************
  343.             Private Sub Form_Load()
  344.             On Local Error GoTo ErrLine
  345.             
  346.             'reset the rate to 1 (normal)
  347.             optPlaybackRate(1).Value = True
  348.             
  349.             'Alter the coordinate system so that we work
  350.             'in pixels (instead of the default twips)
  351.             frmMain.ScaleMode = 3   ' pixels
  352.             
  353.             'Set the granularity for the timer control
  354.             'so that we can display the duration for
  355.             'given video sequence.
  356.             tmrTimer.Interval = 250   '1/4 second intervals
  357.             
  358.             'disable all the control buttons by default
  359.             tbControlBar.Buttons("play").Enabled = False
  360.             tbControlBar.Buttons("stop").Enabled = False
  361.             tbControlBar.Buttons("pause").Enabled = False
  362.             Exit Sub
  363.             
  364. ErrLine:
  365.             Err.Clear
  366.             Exit Sub
  367.             End Sub
  368.             
  369.             
  370.             
  371.             ' ******************************************************************************************************************************
  372.             ' * procedure name: Form_Unload
  373.             ' * procedure description:  Occurs when a form is about to be removed from the screen.
  374.             ' *
  375.             ' ******************************************************************************************************************************
  376.             Private Sub Form_Unload(Cancel As Integer)
  377.             On Local Error GoTo ErrLine
  378.             
  379.             'stop playback
  380.             m_boolVideoRunning = False
  381.             DoEvents
  382.             'cleanup media control
  383.             If ObjPtr(m_objMediaControl) > 0 Then
  384.                m_objMediaControl.Stop
  385.             End If
  386.             'clean-up video window
  387.             If ObjPtr(m_objVideoWindow) > 0 Then
  388.                m_objVideoWindow.Left = Screen.Width * 8
  389.                m_objVideoWindow.Height = Screen.Height * 8
  390.                m_objVideoWindow.Owner = 0          'sets the Owner to NULL
  391.             End If
  392.             
  393.             'clean-up & dereference
  394.             If ObjPtr(m_objBasicAudio) > 0 Then Set m_objBasicAudio = Nothing
  395.             If ObjPtr(m_objBasicVideo) > 0 Then Set m_objBasicVideo = Nothing
  396.             If ObjPtr(m_objMediaControl) > 0 Then Set m_objMediaControl = Nothing
  397.             If ObjPtr(m_objVideoWindow) > 0 Then Set m_objVideoWindow = Nothing
  398.             If ObjPtr(m_objMediaPosition) > 0 Then Set m_objMediaPosition = Nothing
  399.             Exit Sub
  400.             
  401. ErrLine:
  402.             Err.Clear
  403.             Exit Sub
  404.             End Sub
  405.             
  406.             
  407.             ' ******************************************************************************************************************************
  408.             ' * procedure name: mnuFileExit_Click
  409.             ' * procedure description:  Occurs when the "Exit" option is invoked from the "File" option on the main menubar.
  410.             ' *
  411.             ' ******************************************************************************************************************************
  412.             Private Sub mnuFileExit_Click()
  413.             Dim frm As Form
  414.             On Local Error GoTo ErrLine
  415.             
  416.             'unload each loaded form
  417.             For Each frm In Forms
  418.                 frm.Move Screen.Width * 8, Screen.Height * 8
  419.                 Unload frm
  420.                 Set frm = Nothing
  421.             Next
  422.             Exit Sub
  423.             
  424. ErrLine:
  425.             Err.Clear
  426.             Exit Sub
  427.             End Sub
  428.             
  429.             
  430.             ' ******************************************************************************************************************************
  431.             ' * procedure name: mnu_FileExit_Click
  432.             ' * procedure description:   Occurs when the user elects the 'Exit' option via the main 'File' menu.
  433.             ' *
  434.             ' ******************************************************************************************************************************
  435.             Private Sub mnu_FileExit_Click()
  436.             Dim frm As Form
  437.             On Local Error GoTo ErrLine
  438.             
  439.             For Each frm In Forms
  440.                frm.Move Screen.Width * 8, Screen.Height * 8
  441.                frm.Visible = False: Unload frm
  442.             Next
  443.             Exit Sub
  444.             
  445. ErrLine:
  446.             Err.Clear
  447.             Exit Sub
  448.             End Sub
  449.             ' ******************************************************************************************************************************
  450.             ' * procedure name: mnu_FileOpen_Click
  451.             ' * procedure description:   Occurs when the user elects the 'Open' option via the main 'File' menu.
  452.             ' *
  453.             ' ******************************************************************************************************************************
  454.             Private Sub mnu_FileOpen_Click()
  455.             Dim nCount As Long
  456.             On Local Error GoTo ErrLine
  457.             
  458.             ' Use the common file dialog to select a media file
  459.             ' (has the extension .AVI or .MPG.)
  460.             ' Initialize global variables based on the
  461.             ' contents of the file:
  462.             '   m_bstrFileName - name of file name selected by the user
  463.             '   m_dblRunLength = length of the file; duration
  464.             '   m_dblStartPosition - point at which to start playing clip
  465.             '   m_objMediaControl, m_objMediaEvent, m_objMediaPosition,
  466.             '   m_objBasicAudio, m_objVideoWindow - programmable objects
  467.             
  468.             'clean up memory (in case a file is already open)
  469.             Call Form_Unload(True)
  470.             
  471.             'Retrieve the name of an .avi or an .mpg
  472.             'file that the user wishes to view.
  473.             ctrlCommonDialog.Filter = "Media Files (*.mpg;*.avi;*.mov;*.wav;*.mp2;*.mp3)|*.mpg;*.avi;*.mov;*.wav;*.mp2;*.mp3"
  474.             ctrlCommonDialog.ShowOpen
  475.             m_bstrFileName = ctrlCommonDialog.FileName
  476.             
  477.             'Instantiate a filter graph for the requested
  478.             'file format.
  479.             Set m_objMediaControl = New FilgraphManager
  480.             Call m_objMediaControl.RenderFile(m_bstrFileName)
  481.             
  482.             'Setup the IBasicAudio object (this
  483.             'is equivalent to calling QueryInterface()
  484.             'on IFilterGraphManager). Initialize the volume
  485.             'to the maximum value.
  486.             
  487.             ' Some filter graphs don't render audio
  488.             ' In this sample, skip setting volume property
  489.             Set m_objBasicAudio = m_objMediaControl
  490.             m_objBasicAudio.Volume = slVolume.Value
  491.             m_objBasicAudio.Balance = slBalance.Value
  492.             
  493.             'Setup the IVideoWindow object. Remove the
  494.             'caption, border, dialog frame, and scrollbars
  495.             'from the default window. Position the window.
  496.             'Set the parent to the app's form.
  497.             Set m_objVideoWindow = m_objMediaControl
  498.             m_objVideoWindow.WindowStyle = CLng(&H6000000)
  499.             m_objVideoWindow.Top = 0
  500.             m_objVideoWindow.Left = 0
  501.             m_objVideoWindow.Width = picVideoWindow.Width
  502.             m_objVideoWindow.Height = picVideoWindow.Height
  503.             'reset the video window owner
  504.             m_objVideoWindow.Owner = picVideoWindow.hWnd
  505.             
  506.             'Setup the IMediaEvent object for the
  507.             'sample toolbar (run, pause, play).
  508.             Set m_objMediaEvent = m_objMediaControl
  509.             
  510.             'Setup the IMediaPosition object so that we
  511.             'can display the duration of the selected
  512.             'video as well as the elapsed time.
  513.             Set m_objMediaPosition = m_objMediaControl
  514.             
  515.             'set the playback rate given the desired optional
  516.             For nCount = optPlaybackRate.LBound To optPlaybackRate.UBound
  517.                If optPlaybackRate(nCount).Value = True Then
  518.                   Select Case nCount
  519.                   Case 0
  520.                          If ObjPtr(m_objMediaPosition) > 0 Then _
  521.                             m_objMediaPosition.Rate = 0.5
  522.                   Case 1
  523.                          If ObjPtr(m_objMediaPosition) > 0 Then _
  524.                             m_objMediaPosition.Rate = 1
  525.                   Case 2
  526.                          If ObjPtr(m_objMediaPosition) > 0 Then _
  527.                             m_objMediaPosition.Rate = 2
  528.                   End Select
  529.                   Exit For
  530.                End If
  531.             Next
  532.             
  533.             m_dblRunLength = Round(m_objMediaPosition.Duration, 2)
  534.             txtDuration.Text = CStr(m_dblRunLength)
  535.             
  536.             ' Reset start position to 0
  537.             m_dblStartPosition = 0
  538.             
  539.             ' Use user-established playback rate
  540.             m_dblRate = m_objMediaPosition.Rate
  541.             txtRate.Text = CStr(m_dblRate)
  542.             
  543.             'enable run buttons by default
  544.             tbControlBar.Buttons("play").Enabled = True
  545.             tbControlBar.Buttons("stop").Enabled = False
  546.             tbControlBar.Buttons("pause").Enabled = False
  547.             
  548.             'run the media file
  549.             Call tbControlBar_ButtonClick(tbControlBar.Buttons(1))
  550.             Exit Sub
  551.             
  552. ErrLine:
  553.             Err.Clear
  554.             Resume Next
  555.             Exit Sub
  556.             End Sub
  557.             
  558.             
  559.             ' ******************************************************************************************************************************
  560.             ' * procedure name: optPlaybackRate_Click
  561.             ' * procedure description:   Indicates that the contents of a control have changed.
  562.             ' *
  563.             ' ******************************************************************************************************************************
  564.             Private Sub optPlaybackRate_Click(Index As Integer)
  565.             On Local Error GoTo ErrLine
  566.             
  567.             'reset textbox
  568.             Select Case Index
  569.             Case 0
  570.                    If ObjPtr(m_objMediaPosition) > 0 Then _
  571.                       txtRate.Text = 0.5
  572.             Case 1
  573.                    If ObjPtr(m_objMediaPosition) > 0 Then _
  574.                       txtRate.Text = 1
  575.             Case 2
  576.                    If ObjPtr(m_objMediaPosition) > 0 Then _
  577.                       txtRate.Text = 2
  578.             End Select
  579.             
  580.             'reset media playback rate
  581.             If ObjPtr(m_objMediaPosition) > 0 Then
  582.                Select Case Index
  583.                Case 0
  584.                       If ObjPtr(m_objMediaPosition) > 0 Then _
  585.                          m_objMediaPosition.Rate = 0.5
  586.                Case 1
  587.                       If ObjPtr(m_objMediaPosition) > 0 Then _
  588.                          m_objMediaPosition.Rate = 1
  589.                Case 2
  590.                       If ObjPtr(m_objMediaPosition) > 0 Then _
  591.                          m_objMediaPosition.Rate = 2
  592.                End Select
  593.             End If
  594.             Exit Sub
  595.             
  596. ErrLine:
  597.             Err.Clear
  598.             Exit Sub
  599.             End Sub
  600.             ' ******************************************************************************************************************************
  601.             ' * procedure name: slBalance_Change
  602.             ' * procedure description:   Indicates that the contents of a control have changed.
  603.             ' *
  604.             ' ******************************************************************************************************************************
  605.             Private Sub slBalance_Change()
  606.             On Local Error GoTo ErrLine
  607.             
  608.             'Set the balance using the slider
  609.             If ObjPtr(m_objMediaControl) > 0 Then _
  610.                m_objBasicAudio.Balance = slBalance.Value
  611.             Exit Sub
  612.             
  613. ErrLine:
  614.             Err.Clear
  615.             Exit Sub
  616.             End Sub
  617.             
  618.             
  619.             ' ******************************************************************************************************************************
  620.             ' * procedure name: slVolume_Change
  621.             ' * procedure description:   Indicates that the contents of a control have changed.
  622.             ' *
  623.             ' ******************************************************************************************************************************
  624.             Private Sub slVolume_Change()
  625.             On Local Error GoTo ErrLine
  626.             
  627.             'Set the volume using the slider
  628.             If ObjPtr(m_objMediaControl) > 0 Then _
  629.                m_objBasicAudio.Volume = slVolume.Value
  630.             Exit Sub
  631.             
  632. ErrLine:
  633.             Err.Clear
  634.             Exit Sub
  635.             End Sub
  636.             
  637.             
  638.             ' ******************************************************************************************************************************
  639.             ' * procedure name: slBalance_MouseMove
  640.             ' * procedure description:    Occurs when the user moves the mouse.
  641.             ' *
  642.             ' ******************************************************************************************************************************
  643.             Private Sub slBalance_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  644.             On Local Error GoTo ErrLine
  645.             
  646.             'Set the balance using the slider
  647.             If ObjPtr(m_objMediaControl) > 0 Then _
  648.                m_objBasicAudio.Balance = slBalance.Value
  649.             Exit Sub
  650.             
  651. ErrLine:
  652.             Err.Clear
  653.             Exit Sub
  654.             End Sub
  655.             
  656.             
  657.             ' ******************************************************************************************************************************
  658.             ' * procedure name: slVolume_MouseMove
  659.             ' * procedure description:    Occurs when the user moves the mouse.
  660.             ' *
  661.             ' ******************************************************************************************************************************
  662.             Private Sub slVolume_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  663.             On Local Error GoTo ErrLine
  664.             
  665.             'Set the volume using the slider
  666.             If ObjPtr(m_objMediaControl) > 0 Then _
  667.                m_objBasicAudio.Volume = slVolume.Value
  668.             Exit Sub
  669.             
  670. ErrLine:
  671.             Err.Clear
  672.             Exit Sub
  673.             End Sub
  674.             
  675.             
  676.             ' ******************************************************************************************************************************
  677.             ' * procedure name: tbControlBar_ButtonClick
  678.             ' * procedure description:    Occurs when the user clicks on a Button object in a Toolbar control.
  679.             ' *
  680.             ' ******************************************************************************************************************************
  681.             Private Sub tbControlBar_ButtonClick(ByVal Button As Button)
  682.             On Local Error GoTo ErrLine
  683.             
  684.             ' handle buttons on the toolbar
  685.             ' buttons 1, 3 and 5 are defined; 2 and 4 are separators
  686.             ' all DirectShow objects are defined only if the user
  687.             ' has already selected a filename and initialized the objects
  688.             
  689.             ' if the objects aren't defined, avoid errors
  690.             If ObjPtr(m_objMediaControl) > 0 Then
  691.                If Button.Key = "play" Then 'PLAY
  692.                   'Invoke the MediaControl Run() method
  693.                   'and pause the video that is being
  694.                   'displayed through the predefined
  695.                   'filter graph.
  696.                   
  697.                   'Assign specified starting position dependent on state
  698.                   If CLng(m_objMediaPosition.CurrentPosition) < CLng(m_dblStartPosition) Then
  699.                       m_objMediaPosition.CurrentPosition = m_dblStartPosition
  700.                   ElseIf CLng(m_objMediaPosition.CurrentPosition) = CLng(m_dblRunLength) Then
  701.                       m_objMediaPosition.CurrentPosition = m_dblStartPosition
  702.                   End If
  703.                   Call m_objMediaControl.Run
  704.                   m_boolVideoRunning = True
  705.                   'enable/disable control buttons
  706.                   tbControlBar.Buttons("play").Enabled = False
  707.                   tbControlBar.Buttons("stop").Enabled = True
  708.                   tbControlBar.Buttons("pause").Enabled = True
  709.                    
  710.                ElseIf Button.Key = "pause" Then  'PAUSE
  711.                   'Invoke the MediaControl Pause() method
  712.                   'and pause the video that is being
  713.                   'displayed through the predefined
  714.                   'filter graph.
  715.                   Call m_objMediaControl.Pause
  716.                   m_boolVideoRunning = False
  717.                   'enable/disable control buttons
  718.                   tbControlBar.Buttons("play").Enabled = True
  719.                   tbControlBar.Buttons("stop").Enabled = True
  720.                   tbControlBar.Buttons("pause").Enabled = False
  721.                   
  722.                ElseIf Button.Key = "stop" Then  'STOP
  723.                   'Invoke the MediaControl Stop() method
  724.                   'and stop the video that is being
  725.                   'displayed through the predefined
  726.                   'filter graph.
  727.                   
  728.                   Call m_objMediaControl.Stop
  729.                   m_boolVideoRunning = False
  730.                   ' reset to the beginning of the video
  731.                   m_objMediaPosition.CurrentPosition = 0
  732.                   txtElapsed.Text = "0.0"
  733.                   'enable/disable control buttons
  734.                   tbControlBar.Buttons("play").Enabled = True
  735.                   tbControlBar.Buttons("stop").Enabled = False
  736.                   tbControlBar.Buttons("pause").Enabled = False
  737.                End If
  738.             End If
  739.             Exit Sub
  740.             
  741. ErrLine:
  742.             Err.Clear
  743.             Exit Sub
  744.             End Sub
  745.             
  746.             
  747.             ' ******************************************************************************************************************************
  748.             ' * procedure name: tmrTimer_Timer
  749.             ' * procedure description:    Occurs when a preset interval for a Timer control has elapsed.
  750.             ' *
  751.             ' ******************************************************************************************************************************
  752.             Private Sub tmrTimer_Timer()
  753.             Dim nReturnCode As Long
  754.             Dim dblPosition As Double
  755.             On Local Error GoTo ErrLine
  756.             'Retrieve the Elapsed Time and
  757.             'display it in the corresponding
  758.             'textbox.
  759.             
  760.             If m_boolVideoRunning = True Then
  761.             
  762.             'obtain return code
  763.                Call m_objMediaEvent.WaitForCompletion(100, nReturnCode)
  764.                
  765.                
  766.                If nReturnCode = 0 Then
  767.                    'get the current position for display
  768.                    dblPosition = m_objMediaPosition.CurrentPosition
  769.                    txtElapsed.Text = CStr(Round(dblPosition, 2))
  770.                Else
  771.                    txtElapsed.Text = CStr(Round(m_dblRunLength, 2))
  772.                    'enable/disable control buttons
  773.                    tbControlBar.Buttons("play").Enabled = True
  774.                    tbControlBar.Buttons("stop").Enabled = False
  775.                    tbControlBar.Buttons("pause").Enabled = False
  776.                    m_boolVideoRunning = False
  777.                End If
  778.             End If
  779.             Exit Sub
  780.             
  781. ErrLine:
  782.             Err.Clear
  783.             Resume Next
  784.             Exit Sub
  785.             End Sub
  786.