CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Posts
    4

    VB6.0 OLE Control with Video Clip object

    I have an OLE Control on my VB6.0 project form with Video Clip as the object. I have selected a video clip while inserting the control on the form.

    When I run the application, the form and control come up and I can right click on the control resulting in choices in the pop-up display for Play, Edit and Open. If I click on Play, it plays the video clip I selected at development time as expected.

    How can I write code emulate the Play, Edit and Open buttons?

    Thanks

  2. #2
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214

    Re: VB6.0 OLE Control with Video Clip object

    Not sure about Edit, but if your using the Professional Version of Vb, then you will find the multimedia control available in the toolbox that you could use.
    If you find my answers helpful, dont forget to rate me

  3. #3
    Join Date
    Dec 2008
    Posts
    4

    Re: VB6.0 OLE Control with Video Clip object

    Thanks Bill

    The Multimedia Control will play an avi, but it opens it in its own window.

    I want it to play in the ole control I have on the form.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB6.0 OLE Control with Video Clip object

    Here's an old sample...

    Plays quickly on the new machine, but plays on the form...

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    ' DirectShow_Load_Media "\my music\demo.mp3"
     DirectShow_Load_Media App.Path & "\filedel.avi"
     DirectShow_Play
    End Sub
    DirectShow.bas
    Code:
    Option Explicit
    
    Private Const MAX_VOLUME As Long = 100
    Private Const MAX_BALANCE As Long = 100
    Private Const MAX_SPEED As Long = 226
    
    Public DirectShow_Event As IMediaEvent
    Public DirectShow_Control As IMediaControl
    Public DirectShow_Position As IMediaPosition
    Public DirectShow_Audio As IBasicAudio
    Public DirectShow_Video As IBasicVideo
    Public DirectShow_Video_Window As IVideoWindow
    
    Public Video_Media As Boolean
    Public Video_Running As Boolean
    Public Fullscreen_Enabled As Boolean
    Public Fullscreen_Width As Long
    Public Fullscreen_Height As Long
    
    
    Public Function DirectShow_Load_Media(File_Name As String) As Boolean
    
        On Error GoTo Error_Handler
                    
            If Right(File_Name, 4) = ".mp3" Then
                        Video_Media = False
                                Set DirectShow_Control = New FilgraphManager
                DirectShow_Control.RenderFile (File_Name)
            
                Set DirectShow_Audio = DirectShow_Control
                
                DirectShow_Audio.Volume = 0
                DirectShow_Audio.Balance = 0
            
                Set DirectShow_Event = DirectShow_Control
                Set DirectShow_Position = DirectShow_Control
                
                DirectShow_Position.Rate = 1
                
                DirectShow_Position.CurrentPosition = 0
                
            ElseIf Right(File_Name, 4) = ".mpeg" Or _
                   Right(File_Name, 4) = ".mpg" Or _
                   Right(File_Name, 4) = ".avi" Or _
                   Right(File_Name, 4) = ".mov" Then
                               Video_Media = True
                               Set DirectShow_Control = New FilgraphManager
                DirectShow_Control.RenderFile (File_Name)
    
                Set DirectShow_Audio = DirectShow_Control
        
                DirectShow_Audio.Volume = 0
                DirectShow_Audio.Balance = 0
    
                If Fullscreen_Enabled = True Then
                                    Set DirectShow_Video_Window = DirectShow_Control
                    DirectShow_Video_Window.WindowStyle = CLng(&H6000000)
                    DirectShow_Video_Window.Top = 0
                    DirectShow_Video_Window.Left = 0
                    DirectShow_Video_Window.Width = Fullscreen_Width
                    DirectShow_Video_Window.Height = Fullscreen_Height
                    DirectShow_Video_Window.Owner = frmMain.hWnd
                    
                Else
                    Set DirectShow_Video_Window = DirectShow_Control
                    DirectShow_Video_Window.WindowStyle = CLng(&H6000000)
                    DirectShow_Video_Window.Top = 0
                    DirectShow_Video_Window.Left = 0
                    DirectShow_Video_Window.Width = frmMain.ScaleWidth
                    DirectShow_Video_Window.Height = frmMain.ScaleHeight
                    DirectShow_Video_Window.Owner = frmMain.hWnd
                
                End If
                        Set DirectShow_Event = DirectShow_Control
                Set DirectShow_Position = DirectShow_Control
                
                DirectShow_Position.Rate = 1
                
                DirectShow_Position.CurrentPosition = 0
                   
            Else
                        GoTo Error_Handler
            
            End If
    
        DirectShow_Load_Media = True
            Exit Function
    Error_Handler:
    
        DirectShow_Load_Media = False
    
    End Function
    
    
    Public Function DirectShow_Play() As Boolean
            On Error GoTo Error_Handler
        
        If Video_Media = True Then Video_Running = True
            DirectShow_Control.Run
    
        DirectShow_Play = True
            Exit Function
    
    Error_Handler:
        
        DirectShow_Play = False
    
    End Function
    
    Public Function DirectShow_Stop() As Boolean
    
        On Error GoTo Error_Handler
        
        If Video_Media = True Then
                Video_Running = False
                Video_Media = False
            End If
            DirectShow_Control.Stop
            DirectShow_Position.CurrentPosition = 0
    
        DirectShow_Stop = True
            Exit Function
    
    Error_Handler:
    
        DirectShow_Stop = False
    
    End Function
    
    Public Function DirectShow_Pause() As Boolean
    
        On Error GoTo Error_Handler
        
        DirectShow_Control.Stop
    
        DirectShow_Pause = True
            Exit Function
    Error_Handler:
        
        DirectShow_Pause = False
    
    End Function
    
    Public Function DirectShow_Volume(ByVal Volume As Long) As Boolean
    
        On Error GoTo Error_Handler
        
        If Volume >= MAX_VOLUME Then Volume = MAX_VOLUME
        
        If Volume <= 0 Then Volume = 0
        
        DirectShow_Audio.Volume = (Volume * MAX_VOLUME) - 10000
    
        DirectShow_Volume = True
            Exit Function
    Error_Handler:
    
        DirectShow_Volume = False
    
    End Function
    
    Public Function DirectShow_Balance(ByVal Balance As Long) As Boolean
    
        On Error GoTo Error_Handler
        
        If Balance >= MAX_BALANCE Then Balance = MAX_BALANCE
        
        If Balance <= -MAX_BALANCE Then Balance = -MAX_BALANCE
        
        DirectShow_Audio.Balance = Balance * MAX_BALANCE
        
        DirectShow_Balance = True
            Exit Function
    Error_Handler:
    
        DirectShow_Balance = False
    
    End Function
    
    Public Function DirectShow_Speed(ByVal Speed As Single) As Boolean
    
        On Error GoTo Error_Handler
    
        If Speed >= MAX_SPEED Then Speed = MAX_SPEED
        
        If Speed <= 0 Then Speed = 0
    
        DirectShow_Position.Rate = Speed / 100
    
        DirectShow_Speed = True
            Exit Function
    
    Error_Handler:
    
        DirectShow_Speed = False
    
    End Function
    
    Public Function DirectShow_Set_Position(ByVal Hours As Long, ByVal Minutes As Long, ByVal Seconds As Long, Milliseconds As Single) As Boolean
            On Error GoTo Error_Handler
        
        Dim Max_Position As Single
            Dim Position As Double
            Dim Decimal_Milliseconds As Single
            'Keep minutes within range
                Minutes = Minutes Mod 60
            
        'Keep seconds within range
                Seconds = Seconds Mod 60
            
        'Keep milliseconds within range and keep decimal
                Decimal_Milliseconds = Milliseconds - Int(Milliseconds)
            
            Milliseconds = Milliseconds Mod 1000
            
            Milliseconds = Milliseconds + Decimal_Milliseconds
        
        'Convert Minutes & Seconds to Position time
                Position = (Hours * 3600) + (Minutes * 60) + Seconds + (Milliseconds * 0.001)
        
        Max_Position = DirectShow_Position.StopTime
    
        If Position >= Max_Position Then
                Position = 0
            
            GoTo Error_Handler
        
        End If
            If Position <= 0 Then
                Position = 0
            
            GoTo Error_Handler
        
        End If
            DirectShow_Position.CurrentPosition = Position
        
        DirectShow_Set_Position = True
            Exit Function
    Error_Handler:
    
        DirectShow_Set_Position = False
    
    End Function
    
    Public Function DirectShow_End() As Boolean
    
        On Error GoTo Error_Handler
        
        If DirectShow_Loop = False Then
                If DirectShow_Position.CurrentPosition >= DirectShow_Position.StopTime Then DirectShow_Stop
        
        End If
            DirectShow_End = True
            Exit Function
    Error_Handler:
    
        DirectShow_End = False
    
    End Function
    
    Public Function DirectShow_Loop() As Boolean
    
        On Error GoTo Error_Handler
    
        If DirectShow_Position.CurrentPosition >= DirectShow_Position.StopTime Then
                DirectShow_Position.CurrentPosition = 0
        
        End If
            DirectShow_Loop = True
            Exit Function
    Error_Handler:
    
        DirectShow_Loop = False
    
    End Function
    
    Public Sub DirectShow_Shutdown()
    
        Set DirectShow_Video_Window = Nothing
        Set DirectShow_Position = Nothing
        Set DirectShow_Event = Nothing
        Set DirectShow_Audio = Nothing
        Set DirectShow_Control = Nothing
    
    End Sub
    Attached Files Attached Files
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Dec 2008
    Posts
    4

    Re: VB6.0 OLE Control with Video Clip object

    Thanks for the replies.

    The magical method I was looking for was DOVERB().

  6. #6
    Join Date
    Dec 2008
    Posts
    1

    Re: VB6.0 OLE Control with Video Clip object

    You described exactly what I have been trying to do for the past day or so, play a 5 second video clip on a form, when the form opens. Can you post or send me an example of your code using the DoVerb() method?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured