Benoit
Benoit

Reputation: 1

Directshow in VBA VLC ActiveX problem name device

I searched without success in the forums, so I try to get help from you. Thank you in advance

I am testing a code in vba that causes me a problem using the vlc activex. I want to display my webcam. I have two webcams. When I follow the parameter of the name of the webcam, it is not taken into account and it is always the webcam1 that appears.

I use office professional plus 2019 on windows 10. I installed VLC Vetinari which allowed me to have the activex by adding the reference VideoLAN VLC ActiveX Plugin and by adding the additional control VLC ActiveX Pluging and IE Web Plugin v2.

Here is the code that works when I use the shell function. with this code, I manage to define the name of the usb camera that I want and it works.

Sub ConnectWebcamWithShell() 
On Error GoTo ErrorHandler

Dim vlcPath As String vlcPath = """C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe""" ' Path to VLC, adjust if necessary

Dim webcamName As String webcamName = "dshow:// :dshow-vdev=""Logi C270 HD WebCam"" :dshow-adev=none :dshow-size=1280x720 :dshow-fps=30"""

Dim command As String command = vlcPath & " " & webcamName

' Run VLC command 
Shell command, vbNormalFocus

MsgBox "Webcam connected and playing with specified options" Exit Sub

ErrorHandler: MsgBox "Error: " & Err.Description, vbCritical 

End Sub

ere is the code I use in a userform with the activeX control. But here, the option for defining the name of my camera is not taken into account. It is always the other camera that is displayed. The camera that is defined first in my devices. Note that the other option parameters such as options(2) = ":dshow-size=320x240" work well when I change the values ​​to 640x480 for example. But nothing to do for the name of the camera. Would you please have a solution. I tried to add the quotes as necessary when I use shell but nothing works.

Sub ConnectWebcamWithOptions() 
On Error GoTo ErrorHandler

Dim vlc As Object Set vlc = CreateObject("VideoLAN.VLCPlugin.2")

' Check if the VLC object was created successfully If vlc Is Nothing Then MsgBox "Unable to create the VLC object. Make sure that VLC is installed and the ActiveX is registered.", vbCritical Exit Sub End If

' Configure VLC to use the webcam with options 
Dim options(3) As String 
 options(0) = ":dshow-vdev=Logi C270 HD WebCam"
 options(1) = ":dshow-adev=none"
 options(2) = ":dshow-size=640x480"
 'options(2) = ":dshow-size=320x240"
 'options(2) = ":dshow-size=1920x1080"
 'options(2) = ":dshow-size=1280x720"
  options(3) = ":dshow-fps=30" 
 'options(3) = ":dshow-fps=15"
 'options(4) = ":dshow-vdev=none" ' Disable built-in webcam

' Add webcam to playlist with options
 vlc.Playlist.Add "dshow://", "WebCam", options vlc.Playlist.Play

' Wait for video to start playing
 Do While vlc.input.State \<\> 3 ' 3 means video is playing
   DoEvents
 Loop

 MsgBox "Webcam connected and playing with specified options"
 Exit Sub

ErrorHandler: MsgBox "Error: " & Err.Description, vbCritical 

End Sub

I have tried several solutions for naming the camera.

Upvotes: 0

Views: 71

Answers (0)

Related Questions