Hi,
I'm currently evaluating ComfyJ and I have to admit this software looks very promising. However, I have some problems getting a simple program to work which is supposed to play a media file using WMP11 without having a GUI.
Program:
public static void main(String[] args) throws MalformedURLException {
ComFunctions.coInitialize();
String filename = "F:
WM9SDK
WMPSDK9
samples
media
jeanne.wma";
CLSID id = CLSID.createFromProgID("WMPlayer.OCX");
System.out.println("CLSID= " + id);
IWMPPlayer4 player = null;
try {
player = new IWMPPlayer4Impl(id, ClsCtx.INPROC_SERVER);
} catch (ComException e) {
e.printStackTrace();
}
if (player != null) {
BStr theVersion = player.getVersionInfo();
System.out.println("IWMPPlayer4.getVersionInfo(): " + theVersion);
System.out.println("Status= " + player.getStatus());
System.out.println("PlayState= " + player.getPlayState());
System.out.println("ErrorCount= " + player.getError().getErrorCount());
player.setURL(new BStr(filename));
System.out.println("Status= " + player.getStatus());
System.out.println("PlayState= " + player.getPlayState());
IWMPControls theControls = player.getControls();
theControls.play();
IWMPMedia theCurrentItem = theControls.getCurrentItem();
System.out.println("CurrentItem name= " + theCurrentItem.getName());
System.out.println("CurrentItem source url= " + theCurrentItem.getSourceURL());
for (int i = 0; i < 50; i++) {
System.out.println("Status= " + player.getStatus());
System.out.println("PlayState= " + player.getPlayState());
System.out.println("ErrorCount= " + player.getError().getErrorCount());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
Output:
CLSID= {6BF52A52-394A-11D3-B153-00C04F79FAA6}
IWMPPlayer4.getVersionInfo(): 11.0.5721.5230
Status=
PlayState= 0
ErrorCount= 0
Status= Medium wird geöffnet...
PlayState= 9 <- Transitioning
CurrentItem name= jeanne
CurrentItem source url= F:\WM9SDK\WMPSDK9\samples\media\jeanne.wma
Status= Medium wird geöffnet...
PlayState= 9
ErrorCount= 0
Status= Medium wird geöffnet...
PlayState= 9
ErrorCount= 0
Status= Medium wird geöffnet...
Of course, this works with the sample code you provided, however this sample is with gui.
The code is quite straight forward, as I think. There are no COM exceptions and if I try to access the MediaCollection this works as well (corrent number of media items returned). As I'm new to COM, I might be missing something fundamental (section 4.5 of programing guide was a little bit too much magic for me...) and I'd be quite happy if you could help me out.
Cheers,
Tedd