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
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?
Are you running Vista? If so, this may be the solution:
http://j-walkblog.com/index.php?/weblog/posts/eliminating_the_windows_media_player_delay/
I don’t know about David, but I’m running Excel 2003 on Windows XP.
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
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.
This worked for me fine in Excel 2007 and WinXP SP2. But I did experience the delay when I just used your code Dick.
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
Dear friend, I had an idea: I’ve developed a simple audio player in Excel using VBA and some Visual Basic objects. I’ve uploaded the entire file: here’s the link.
http://rapidshare.com/files/63158756/example1.xls.html
Give me an opinion.
p.s. Sorry I’m an Italian boy.
[…] Dose of Excel?????? « Windows Media Player Delay,???Excel?Windows […]
I have a workbook that uses an API to play videos, it a bit more controllable than the old media player – good for trying to spot spooof videos too!
http://www.methodsinexcel.co.uk/Downloads/Vedio%20API.xls
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