Windows Media Player Delay

David wants to know why the WMP control won’t start playing right away. I’ll be damned if I know. Maybe you can tell us. First, show the Control Toolbox and click on More Controls. Find the Windows Media Player control and put it on Sheet1. Next, put these subs in a standard module:

Public Sub assign_and_play()
   
    Sheet1.WindowsMediaPlayer1.URL = “C:MyWav.wma”
    Sheet1.WindowsMediaPlayer1.Controls.Play
 
    Application.Wait (Now + TimeValue(“00:00:05”))
   
    MsgBox “me”
   
End Sub
 
Public Sub just_play()
 
    Sheet1.WindowsMediaPlayer1.Controls.Play
    Application.Wait (Now + TimeValue(“00:00:05”))
   
End Sub

Change the URL line to point to a file on your computer. If you run the first sub, the WMP control won’t start playing for five seconds. Oddly, it starts playing before you dismiss the message box. So it’s not that it’s waiting until the end of the sub.

The second sub, just_play, starts playing immediately. It doesn’t wait for Application.Wait.

What the heck is going on here?

Posted in Uncategorized

9 thoughts on “Windows Media Player Delay

  1. I use a mediaplayer to load and play various silly sounds at buttonclicks -it’s a Tv gameshow app. I remember having problems with delays until I added
    Me.Player.settings.autoStart = False
    in the initialization code, before assigning url . After that it’s blistering fast -one player handles all the sound files. This works fine in my Excel test:

    Public Sub assign_and_play()
    Sheet1.Player.settings.autoStart = False
    DoEvents
    Sheet1.Player.URL = “C:WINDOWSMediaChord.wav”
    DoEvents
    Sheet1.Player.Controls.Play
    End Sub

  2. I should add that the mediaplayer control has lots of features that’s not available in the VBA object model, like vizualisation. Making it depend very much on last “normal” use. Explore all settings properties and set as much desired functionality as possible by code, to ensure that it works as the code wants when used as a control.

  3. This worked for me fine in Excel 2007 and WinXP SP2. But I did experience the delay when I just used your code Dick.

    Option Explicit

    Public Sub assign_and_play()
       
        Sheet1.WindowsMediaPlayer1.URL = “C:MyWav.wma”

        Do While Sheet1.WindowsMediaPlayer1.openState <> 13 ‘wmposMediaOpen
           DoEvents
        Loop

        Sheet1.WindowsMediaPlayer1.Controls.Play
     
        ‘Application.Wait (Now + TimeValue(“00:00:05”))
     
        MsgBox “Me”
           
    End Sub
     
    Public Sub just_play()
     
        Sheet1.WindowsMediaPlayer1.Controls.Play
        ‘Application.Wait (Now + TimeValue(“00:00:05”))
     
    End Sub

  4. Hey,

    Sorry to bug you guys, because I am not a code writer but I’m looking for a possible copy and paste solution for a problem I’m having. I need to insert a windows media player inside an excel sheet, and then be able to view a DVD playing inside my computers DVD player. Is there a way to point the WMP controls to the DVD player with VB or something even moronishly simple.

    Thanks

    bc

Leave a Reply

Your email address will not be published. Required fields are marked *