home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / vbdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-05-07  |  16.4 KB  |  478 lines

  1. VERSION 4.00
  2. Begin VB.Form frmMain 
  3.    Caption         =   "ActiveMovie VB Sample"
  4.    ClientHeight    =   6465
  5.    ClientLeft      =   3135
  6.    ClientTop       =   1290
  7.    ClientWidth     =   5850
  8.    ClipControls    =   0   'False
  9.    Height          =   7155
  10.    Left            =   3075
  11.    LinkTopic       =   "frmMain"
  12.    ScaleHeight     =   6465
  13.    ScaleWidth      =   5850
  14.    Top             =   660
  15.    Width           =   5970
  16.    Begin VB.Frame frameBalance 
  17.       Caption         =   "Balance"
  18.       Height          =   1215
  19.       Left            =   2880
  20.       TabIndex        =   13
  21.       Top             =   1560
  22.       Width           =   2295
  23.       Begin VB.Label lblRight 
  24.          Caption         =   "Right"
  25.          Height          =   255
  26.          Left            =   1680
  27.          TabIndex        =   16
  28.          Top             =   840
  29.          Width           =   495
  30.       End
  31.       Begin VB.Label lblLeft 
  32.          Caption         =   "Left"
  33.          Height          =   255
  34.          Left            =   120
  35.          TabIndex        =   15
  36.          Top             =   840
  37.          Width           =   495
  38.       End
  39.       Begin ComctlLib.Slider slBalance 
  40.          Height          =   504
  41.          Left            =   120
  42.          TabIndex        =   14
  43.          Top             =   240
  44.          Width           =   2052
  45.          _Version        =   65536
  46.          _ExtentX        =   3625
  47.          _ExtentY        =   900
  48.          _StockProps     =   64
  49.          Max             =   10000
  50.          Min             =   -10000
  51.          TickStyle       =   2
  52.          TickFrequency   =   2000
  53.       End
  54.    End
  55.    Begin VB.Frame frameVideoControls 
  56.       Caption         =   "Video"
  57.       Height          =   1335
  58.       Left            =   240
  59.       TabIndex        =   10
  60.       Top             =   0
  61.       Width           =   2295
  62.       Begin ComctlLib.Toolbar Toolbar1 
  63.          Height          =   600
  64.          Left            =   240
  65.          TabIndex        =   12
  66.          Top             =   360
  67.          Width           =   1935
  68.          _Version        =   65536
  69.          _ExtentX        =   3413
  70.          _ExtentY        =   1058
  71.          _StockProps     =   96
  72.          ImageList       =   "ImageList1"
  73.          ButtonWidth     =   979
  74.          ButtonHeight    =   953
  75.          NumButtons      =   5
  76.          i1              =   "vbdemo.frx":0000
  77.          i2              =   "vbdemo.frx":01A3
  78.          i3              =   "vbdemo.frx":0342
  79.          i4              =   "vbdemo.frx":04E5
  80.          i5              =   "vbdemo.frx":0684
  81.          AlignSet        =   -1  'True
  82.       End
  83.    End
  84.    Begin VB.TextBox txtRate 
  85.       BackColor       =   &H00000000&
  86.       BeginProperty Font 
  87.          name            =   "Terminal"
  88.          charset         =   255
  89.          weight          =   700
  90.          size            =   6
  91.          underline       =   0   'False
  92.          italic          =   0   'False
  93.          strikethrough   =   0   'False
  94.       EndProperty
  95.       ForeColor       =   &H00FFFFFF&
  96.       Height          =   270
  97.       Left            =   4440
  98.       TabIndex        =   7
  99.       Top             =   1200
  100.       Width           =   855
  101.    End
  102.    Begin VB.TextBox txtStart 
  103.       BackColor       =   &H00000000&
  104.       BeginProperty Font 
  105.          name            =   "Terminal"
  106.          charset         =   255
  107.          weight          =   700
  108.          size            =   6
  109.          underline       =   0   'False
  110.          italic          =   0   'False
  111.          strikethrough   =   0   'False
  112.       EndProperty
  113.       ForeColor       =   &H00FFFFFF&
  114.       Height          =   270
  115.       Left            =   4440
  116.       TabIndex        =   6
  117.       Top             =   840
  118.       Width           =   855
  119.    End
  120.    Begin VB.TextBox txtElapsed 
  121.       Alignment       =   2  'Center
  122.       BackColor       =   &H00000000&
  123.       BeginProperty Font 
  124.          name            =   "Terminal"
  125.          charset         =   255
  126.          weight          =   700
  127.          size            =   6
  128.          underline       =   0   'False
  129.          italic          =   0   'False
  130.          strikethrough   =   0   'False
  131.       EndProperty
  132.       ForeColor       =   &H00FFFFFF&
  133.       Height          =   270
  134.       Left            =   4440
  135.       TabIndex        =   4
  136.       Top             =   480
  137.       Width           =   855
  138.    End
  139.    Begin VB.Timer Timer1 
  140.       Left            =   5160
  141.       Top             =   4680
  142.    End
  143.    Begin VB.TextBox txtDuration 
  144.       Alignment       =   2  'Center
  145.       BackColor       =   &H00000000&
  146.       BeginProperty Font 
  147.          name            =   "Terminal"
  148.          charset         =   255
  149.          weight          =   700
  150.          size            =   6
  151.          underline       =   0   'False
  152.          italic          =   0   'False
  153.          strikethrough   =   0   'False
  154.       EndProperty
  155.       ForeColor       =   &H00FFFFFF&
  156.       Height          =   270
  157.       Left            =   4440
  158.       TabIndex        =   3
  159.       Top             =   120
  160.       Width           =   855
  161.    End
  162.    Begin VB.Frame frameVolume 
  163.       Caption         =   "Volume"
  164.       Height          =   1215
  165.       Left            =   360
  166.       TabIndex        =   0
  167.       Top             =   1560
  168.       Width           =   2295
  169.       Begin ComctlLib.Slider slVolume 
  170.          Height          =   504
  171.          Left            =   120
  172.          TabIndex        =   11
  173.          Top             =   240
  174.          Width           =   2052
  175.          _Version        =   65536
  176.          _ExtentX        =   3625
  177.          _ExtentY        =   900
  178.          _StockProps     =   64
  179.          Max             =   0
  180.          Min             =   -10000
  181.          TickStyle       =   2
  182.          TickFrequency   =   1000
  183.       End
  184.       Begin VB.Label lblMax 
  185.          Caption         =   "Max"
  186.          Height          =   255
  187.          Left            =   1800
  188.          TabIndex        =   2
  189.          Top             =   840
  190.          Width           =   375
  191.       End
  192.       Begin VB.Label lblMin 
  193.          Caption         =   "Min"
  194.          Height          =   255
  195.          Left            =   120
  196.          TabIndex        =   1
  197.          Top             =   840
  198.          Width           =   495
  199.       End
  200.    End
  201.    Begin VB.Label lblDuration 
  202.       Caption         =   "Length (Sec):"
  203.       Height          =   255
  204.       Left            =   2760
  205.       TabIndex        =   17
  206.       Top             =   120
  207.       Width           =   1455
  208.    End
  209.    Begin ComctlLib.ImageList ImageList1 
  210.       Left            =   5040
  211.       Top             =   3840
  212.       _Version        =   65536
  213.       _ExtentX        =   1005
  214.       _ExtentY        =   1005
  215.       _StockProps     =   1
  216.       BackColor       =   -2147483643
  217.       ImageWidth      =   16
  218.       ImageHeight     =   16
  219.       MaskColor       =   12632256
  220.       NumImages       =   3
  221.       i1              =   "vbdemo.frx":0827
  222.       i2              =   "vbdemo.frx":09DE
  223.       i3              =   "vbdemo.frx":0B95
  224.    End
  225.    Begin MSComDlg.CommonDialog CommonDialog1 
  226.       Left            =   4920
  227.       Top             =   3120
  228.       _Version        =   65536
  229.       _ExtentX        =   847
  230.       _ExtentY        =   847
  231.       _StockProps     =   0
  232.    End
  233.    Begin VB.Label lblRate 
  234.       Caption         =   "Playback speed:"
  235.       Height          =   255
  236.       Left            =   2760
  237.       TabIndex        =   9
  238.       Top             =   1200
  239.       Width           =   1335
  240.    End
  241.    Begin VB.Label lblStart 
  242.       Caption         =   "Start position (Sec):"
  243.       Height          =   255
  244.       Left            =   2760
  245.       TabIndex        =   8
  246.       Top             =   840
  247.       Width           =   1455
  248.    End
  249.    Begin VB.Label lblElapsed 
  250.       Caption         =   "Elapsed Time (Sec):"
  251.       Height          =   252
  252.       Left            =   2760
  253.       TabIndex        =   5
  254.       Top             =   480
  255.       Width           =   1572
  256.    End
  257.    Begin VB.Shape Shape1 
  258.       BackStyle       =   1  'Opaque
  259.       BorderColor     =   &H00808080&
  260.       BorderWidth     =   4
  261.       Height          =   3135
  262.       Left            =   240
  263.       Top             =   3000
  264.       Width           =   4095
  265.    End
  266.    Begin VB.Menu mnu_File 
  267.       Caption         =   "&File"
  268.       Begin VB.Menu mnu_FileOpen 
  269.          Caption         =   "&Open"
  270.       End
  271.       Begin VB.Menu mnu_FileExit 
  272.          Caption         =   "E&xit"
  273.       End
  274.    End
  275. Attribute VB_Name = "frmMain"
  276. Attribute VB_Creatable = False
  277. Attribute VB_Exposed = False
  278. ' ActiveMovie SDK - VB4 interface sample
  279. ' Copyright 1996 Microsoft Corporation
  280. ' This sample demonstrates Visual Basic 4.0 use of the
  281. ' ActiveMovie interfaces that are in FilgraphManager.
  282. ' This sample defines the following variable prefixes:
  283. '  g_dbl - global double;
  284. '  g_f   - global flag (Boolean);
  285. '  g_obj - object;
  286. '  g_str - string
  287. Dim g_objVideoWindow As IVideoWindow       'VideoWindow Object
  288. Dim g_objMediaControl As IMediaControl     'MediaControl Object
  289. Dim g_objMediaPosition As IMediaPosition   'MediaPosition Object
  290. Dim g_objBasicAudio  As IBasicAudio        'Basic Audio Object
  291. Dim g_objBasicVideo As IBasicVideo         'Basic Video Object
  292. Dim g_strFileName As String      'Name retrieved with FileOpenDlg
  293. Dim g_dblRunLength As Double     'Global duration in seconds
  294. Dim g_dblStartPosition As Double 'Global start position in seconds
  295. Dim g_dblRate As Double          'Global rate
  296. Dim g_fVideoRun As Boolean       'Flag used to trigger clock
  297. Private Sub Form_Load()
  298.     'Alter the coordinate system so that we work
  299.     'in pixels (instead of the default twips)
  300.     frmMain.ScaleMode = 3   ' pixels
  301.     'Set the granularity for the timer control
  302.     'so that we can display the duration for
  303.     'given video sequence.
  304.     Timer1.Interval = 1000 '1 second intervals
  305. End Sub
  306. Private Sub mnu_FileExit_Click()
  307. ' clean up memory
  308.     If Not g_objMediaControl Is Nothing Then
  309.         g_objMediaControl.Stop
  310.     End If
  311.     Set g_objVideoWindow = Nothing
  312.     Set g_objMediaControl = Nothing
  313.     Set g_objMediaPosition = Nothing
  314.     Set g_objBasicAudio = Nothing
  315.     Set g_objBasicVideo = Nothing
  316.     End
  317. End Sub
  318. Private Sub mnu_FileOpen_Click()
  319. ' Use the common file dialog to select an ActiveMovie file
  320. ' (has the extension .AVI or .MPG.)
  321. ' Initialize global variables based on the
  322. ' contents of the file:
  323. '   g_strFileName - name of file name selected by the user
  324. '   g_dblRunLength = length of the file; duration
  325. '   g_dblStartPosition - point at which to start playing clip
  326. '   g_objMediaControl, g_objMediaEvent, g_objMediaPosition,
  327. '     g_objBasicAudio, g_objVideoWindow - programmable objects
  328.     'Retrieve the name of an .avi or an .mpg
  329.     'file that the user wishes to view.
  330.     CommonDialog1.Filter = "ActiveMovie files (*.mpg;*.avi;*.mov)|*.mpg;*.avi;*.mov"
  331.     CommonDialog1.ShowOpen
  332.     g_strFileName = CommonDialog1.filename
  333.     'Verify that correct filename was selected
  334.     If (InStr(1, g_strFileName, ".avi", 1)) Or (InStr(1, g_strFileName, ".mpg", 1) Or (InStr(1, g_strFileName, ".mov", 1))) Then
  335.     Else
  336.         MsgBox "Invalid Filename Selected!", "ActiveMovie sample"
  337.         Exit Sub
  338.     End If
  339.     'Instantiate a filter graph for the requested
  340.     'file format.
  341.     Set g_objMediaControl = New FilgraphManager
  342.     If g_objMediaControl Is Nothing Then
  343.         MsgBox "Cannot create the IMediaControl object"
  344.         Exit Sub
  345.     End If
  346.         
  347.     g_objMediaControl.RenderFile (g_strFileName)
  348.     'Setup the IBasicAudio object (this
  349.     'is equivalent to calling QueryInterface()
  350.     'on IFilterGraphManager). Initialize the volume
  351.     'to the maximum value.
  352.     ' Some filter graphs don't render audio
  353.     ' In this sample, skip setting volume property
  354.     Set g_objBasicAudio = g_objMediaControl
  355.     On Error Resume Next
  356.     g_objBasicAudio.Volume = slVolume.Value
  357.     'Setup the IVideoWindow object. Remove the
  358.     'caption, border, dialog frame, and scrollbars
  359.     'from the default window. Position the window.
  360.     'Set the parent to the app's form.
  361.     Set g_objVideoWindow = g_objMediaControl
  362.     g_objVideoWindow.WindowStyle = CLng(&H6000000)
  363.     g_objVideoWindow.Left = CLng(Shape1.Left)
  364.     g_objVideoWindow.Top = CLng(Shape1.Top)
  365.     Shape1.Width = g_objVideoWindow.Width
  366.     Shape1.Height = g_objVideoWindow.Height
  367.     g_objVideoWindow.Owner = frmMain.hWnd
  368.          
  369.     'Setup the IMediaEvent object for the
  370.     'sample toolbar (run, pause, play).
  371.     Set g_objMediaEvent = g_objMediaControl
  372.     'Setup the IMediaPosition object so that we
  373.     'can display the duration of the selected
  374.     'video as well as the elapsed time.
  375.     Set g_objMediaPosition = g_objMediaControl
  376.     g_dblRunLength = g_objMediaPosition.Duration
  377.     txtDuration.Text = CStr(g_dblRunLength)
  378.     ' reset start position to 0
  379.     g_dblStartPosition = 0#
  380.     txtStart.Text = CDbl(g_dblStartPosition)
  381.     ' use user-established playback rate
  382.     g_dblRate = g_objMediaPosition.Rate
  383.     txtRate.Text = CStr(g_dblRate)
  384. End Sub
  385. Private Sub slVolume_Change()
  386.     'Set the volume on the slider
  387.     g_objBasicAudio.Volume = slVolume.Value
  388. End Sub
  389. Private Sub slBalance_Click()
  390.     'Set the balance using the slider
  391.     g_objBasicAudio.Balance = slBalance.Value
  392. End Sub
  393. Private Sub txtStart_KeyDown(KeyCode As Integer, Shift As Integer)
  394. ' handle user input to change the start position
  395. If KeyCode = vbKeyReturn Then
  396.     If g_objMediaPosition Is Nothing Then
  397.         Exit Sub
  398.     ElseIf CDbl(txtStart.Text) > g_dblRunLength Then
  399.         MsgBox "Specified position invalid: re-enter new position."
  400.     ElseIf CDbl(txtStart.Text) < 0 Then
  401.         MsgBox "Specified position invalid: re-enter new position."
  402.     ElseIf CStr(txtStart.Text) <> "" Then
  403.         g_dblStartPosition = CDbl(txtStart.Text)
  404.         g_objMediaPosition.CurrentPosition = g_dblStartPosition
  405.     End If
  406. End If
  407. End Sub
  408. Private Sub txtRate_KeyDown(KeyCode As Integer, Shift As Integer)
  409. ' ActiveMovie VB sample
  410. ' handle user updates to the Rate value
  411. If KeyCode = vbKeyReturn Then
  412.     If g_objMediaPosition Is Nothing Then
  413.         Exit Sub
  414.     ElseIf CDbl(txtRate.Text) < 0# Then
  415.         MsgBox "Negative values invalid: re-enter value between 0 and 2.0"
  416.     ElseIf CStr(txtRate.Text) <> "" Then
  417.         g_dblRate = CDbl(txtRate.Text)
  418.         g_objMediaPosition.Rate = g_dblRate
  419.     End If
  420. End If
  421. End Sub
  422. Private Sub Timer1_Timer()
  423.     'Retrieve the Elapsed Time and
  424.     'display it in the corresponding
  425.     'textbox.
  426. Dim Dbl As Double
  427.     If g_fVideoRun = True Then
  428.         Dbl = g_objMediaPosition.CurrentPosition
  429.         If Dbl < g_dblRunLength Then
  430.             txtElapsed.Text = CStr(Dbl)
  431.         Else
  432.             txtElapsed.Text = CStr(g_dblRunLength)
  433.         End If
  434.     End If
  435. End Sub
  436. Private Sub Toolbar1_ButtonClick(ByVal Button As Button)
  437. ' handle buttons on the toolbar
  438. ' buttons 1, 3 and 5 are defined; 2 and 4 are separators
  439. ' all ActiveMovie objects are defined only if the user
  440. ' has already selected a filename and initialized the objects
  441.     ' if the objects aren't defined, avoid errors
  442.     If g_objMediaControl Is Nothing Then
  443.         Exit Sub
  444.     End If
  445.     If Button.Index = 1 Then 'PLAY
  446.         'Invoke the MediaControl Run() method
  447.         'and play the video through the predefined
  448.         'filter graph.
  449.         
  450.         ' Use specified starting position
  451.         If g_objMediaPosition.CurrentPosition < g_dblStartPosition Then
  452.             g_objMediaPosition.CurrentPosition = g_dblStartPosition
  453.         End If
  454.         g_objMediaControl.Run
  455.         g_fVideoRun = True
  456.             
  457.     ElseIf Button.Index = 3 Then  'PAUSE
  458.         'Invoke the MediaControl Pause() method
  459.         'and pause the video that is being
  460.         'displayed through the predefined
  461.         'filter graph.
  462.         g_objMediaControl.Pause
  463.         g_fVideoRun = False
  464.         
  465.     ElseIf Button.Index = 5 Then  'STOP
  466.         'Invoke the MediaControl Stop() method
  467.         'and stop the video that is being
  468.         'displayed through the predefined
  469.         'filter graph.
  470.         g_objMediaControl.Stop
  471.         g_fVideoRun = False
  472.         ' reset to the beginning of the video
  473.         g_objMediaPosition.CurrentPosition = 0
  474.         txtElapsed.Text = "0.0"
  475.         
  476.     End If
  477. End Sub
  478.