Results 1 to 13 of 13
  1. #1
    Join Date
    Mar 2023
    Posts
    9

    Video in webbrowser control in Access Form

    Hello Forum Members:

    I have a webbrowser control in a Form.
    WebBrowser1.Application = Me.Location.Value
    or
    Me.WebBrowser1.Hyperlink = Me.Location.Value

    I put it in Private Sub Form_Current(), Private Sub OpenFile_Click(), or Private Sub Play_Click(), but it does not play inside the webbrowser control.
    Instead it tries to open in Windows Media Player.

    Location has PDF, JPEG, GIF, MP4, AVI, etc.
    Webrowser1 can show PDF, JPEG, GIF, but cannot play a video inside.

    Would you please guide me to a right direction?
    Thank you.

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    The original web browser definitely won’t, not sure about the new web browser. If that is what you are using then I suspect not possible.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    It would appear you have to use different code for the file types?
    ChatGPT shows for video files
    Code:
    Private Sub Form_Load()
        Dim filePath As String
        Dim htmlPath As String
        Dim fileNum As Integer
        Dim htmlContent As String
        
        ' Path to media file (MP4/MP3)
        filePath = "C:\Media\sample.mp4"
        
        ' Path to temporary HTML file
        htmlPath = Environ("TEMP") & "\playmedia.html"
        
        ' HTML content with embedded video tag
        htmlContent = "<html><body>" & _
                      "<video width='600' controls autoplay>" & _
                      "<source src='file:///" & Replace(filePath, "\", "/") & "' type='video/mp4'>" & _
                      "Your browser does not support the video tag." & _
                      "</video></body></html>"
        
        ' Write HTML to temp file
        fileNum = FreeFile
        Open htmlPath For Output As #fileNum
        Print #fileNum, htmlContent
        Close #fileNum
    
    
        ' Load HTML file into WebBrowser
        Me.WebBrowser0.Navigate htmlPath
    End Sub
    and comments For audio files, just use <audio> instead of <video>.

    To show files
    Code:
    Private Sub Form_Load()
        Dim filePath As String
        
        ' Set path to the file you want to show
        filePath = "C:\Users\YourName\Documents\sample.pdf"  ' Can also be .html, .jpg, .txt, etc.
        
        ' Check if file exists
        If Dir(filePath) <> "" Then
            Me.WebBrowser0.Navigate filePath
        Else
            MsgBox "File not found: " & filePath, vbExclamation
        End If
    End Sub
    In both it appears you need to use the .Navigate method.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Yes you can play a video in an Edge browser control. For example:

    Click image for larger version. 

Name:	Capture.jpg 
Views:	36 
Size:	120.5 KB 
ID:	52988

    The code used here is very simple.
    The listbox after update event selects the URL and displays it in a textbox.
    The browser control then navigates to that URL

    Code:
    Private Sub lstURL_AfterUpdate()    
        Me.txtWebAddress2 = Me.lstURL
        DoEvents    
    
        Me.EdgeBrowser2.Navigate Me.txtWebAddress2    
    End Sub
    The videos must be stored online for this to work
    It doesn't work for local video files even when prefixing with the URL with https://msaccess

    However another approach that does work for local and online files is to embed a media player ActiveX control on your form
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    Join Date
    Mar 2023
    Posts
    9
    Hello everyone,

    Thank you very much for posing various suggestions.
    I am using Access on Office 2021 and this version does not offer the newer web browser control, so I am out of luck.
    I even tried to change to new web browser control, but Access just crashes.
    Then, I changed as follows:
    Web Browser Control with Location1 (JPEG, GIF, PDF, etc.), which is located on local drive.
    Windows Media ActiveX Control with Location2 (MPEG, AVI, etc.), which is located on local drive.
    Now, I have 2 smaller windows on one screen instead.

    Thank you gain, everyone!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    I have Office 2021.
    Form with Windows Media Player
    Code loads file then I have to click Play twice although it should play automatically. I watched a demo which does.
    Code:
    Sub btnLoadVideo_Click()
    Me.wmp1.URL = "C:\Users\June\test.mp4"
    End Sub
    Might find this of interest https://stackoverflow.com/questions/...es-not-support
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Join Date
    Mar 2023
    Posts
    9
    Hello June7

    My Media ActiveX Control automatically plays video in a Form.
    I put the following:
    Private Sub Form_Current()
    Me.WMP.URL = Me.Location.Value
    End Sub
    Then, it should play the video automatically.

    Thank you.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    My code is in a button Click event on unbound form.
    Me.wmp1.URL = "C:\Users\June\test.mp4"

    When form opens, the player looks like it tried to play but stops partway. I then have to click the play button twice.

    At least it works properly for you. Not something I really need, just testing.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    you can Overlap those two ActiveX controls (Webbrowser and WMP).
    and on just Hide the WMP first.
    on the Load event, check the Extension of the file.
    If the extension is a Video file extension, just Hide the webbrowser and Unhide the WMP
    and play the media using WMP control.
    Same with other extensions, just check first and Hide/Unhide appropriate controls.

  10. #10
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    You could try something along the lines of this quick example.

    When you open the app it will create a folder "MyFiles" in the same folder as the app. Put some pdf and video files in the MyFiles folder and click on the Reload list button.
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    here is a single webbrowser (A2021).
    part of the code was from Mr.Gasman code.
    if you see Yellow warning message, when you select a Video,
    just Click on the yellow message and Choose "Allow blocked content..." to play it.

    will show Images, PDFs and video files.
    Click image for larger version. 

Name:	block_cont.png 
Views:	16 
Size:	9.1 KB 
ID:	52994
    Attached Files Attached Files

  12. #12
    Join Date
    Mar 2023
    Posts
    9
    Hello Everyone

    Thank you for suggesting a couple of ideas.
    The tab control (PDF + Vide) is a good idea, and it is functioning. Just positioning or anchoring the Windows Media Player Control inside the tab is not working well. I just need to spend some time to figure this out.
    Once again, thank you very much!!

  13. #13
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    I don't believe you can size the media player by dragging it to size. It must be done by code. If you notice in my example I set the height and width. It's done in twips so I use 6*1440 to represent 6"

    Also note that if you want to add commands like pause or stop, etc. you need to reference the media player object
    WindowsMediaPlayer0.Object.Controls.stop
    WindowsMediaPlayer0.Object.Controls.pause
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-09-2020, 06:10 AM
  2. Google Maps in webbrowser control
    By bfc in forum Forms
    Replies: 10
    Last Post: 08-27-2014, 10:53 PM
  3. WebBrowser Control to use Chrome?
    By kdbailey in forum Access
    Replies: 2
    Last Post: 07-15-2014, 11:30 AM
  4. sizing a url within a webbrowser control
    By Kirsti in forum Programming
    Replies: 4
    Last Post: 11-06-2012, 06:10 PM
  5. Landscape Orientation-WebBrowser Control
    By mwolfod in forum Forms
    Replies: 0
    Last Post: 04-11-2011, 08:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums