The Windows Media Player ActiveX control is a byzantine morass of simlarly named and akwardly accessed properties and methods. Here is the entry to the labyrinth: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmplay10/mmp_sdk/controlreference.asp
I don't want to scare you, but it can be intimidating at first. Once you have worked with it a while, things start to get easier as you get the hang of what's going on. The Event Wizard, under the Script menu in the DX Script editor, is also very helpful for exploring and finding events.
So, if we have a WMP ActiveX object set up, and want to play a file that has been added as a custom file to the project, one way we can play the file is like this.
Create another DX-object. Sounds like you have this. This will be our "Play" button. It doesn't matter which object you add the custom file to, so just be sure you can keep track of that.
Anyway, we have a new DX Object. Give it an ID in the Summary panel, like "PlayButton" or something, and add a script. For this example, I named the WMP ActiveX object "WMPlayerTest"
This is a sample script for the PlayButton object:
Dim objPlayer Set objPlayer = DesktopX.ScriptObject("WMPlayerTest") ' Called when the script is executed Sub Object_OnScriptEnter End Sub
Sub Object_OnLButtonUp(x, y, d) If d Then Exit Sub objPlayer.Control.currentMedia = objPlayer.Control.newMedia(Object.Directory & "popcorn.mp3") objPlayer.Control.controls.play End Sub
' Called when the script is terminated Sub Object_OnScriptExit Set objPlayer = Nothing End Sub
|
Besides the standard vbs shorthand and DX events, there are (at least) three things happening here, all in the OnLButtonUp subroutine.
First, we must tell the WMPlayer what to play, that is, what the
currentMedia should be. This isn't just a filepath. This is a
Media Object which we create with our file path and the
newMedia method.
That all happens in the line,
objPlayer.Control.currentMedia = objPlayer.Control.newMedia(Object.Directory & "popcorn.mp3")
The (Object.Directory & "popcorn.mp3") bit is a full file path, and my favored way of accessing files added as custom files.
Once we have told the WMPlayer what the currentMedia is, we just need to set it playing. Here is an example of where I get confused sometimes, or at least leave out a bit the first time and have to go back and fix it.
objPlayer.Control.controls.Play
"objPlayer" is the DXScriptObject that is the ActiveX player
"Control" tell DX we want to work with the ActiveX control, and not the DX or other namespace.
"controls" tells the WMP object that we want to use the
Controls object which has all the standards (play, pause, stop, etc).
and finally, we add the "Play" as the command
I hope that has been some help. In a real widget you may want more robust error checking and, possibly, a stop button!