I'm using MPlayer in my java application. According to its doc, it's needed that I tell to MPlayer the window ID for embedding it. I'm doing this like that:
long winid = 0; //Window ID.
if (osName.startsWith("Windows")){
final Class<?> cl = Class.forName("sun.awt.windows.WComponentPeer");
java.lang.reflect.Field f = cl.getDeclaredField("hwnd");
f.setAccessible(true);
winid = f.getLong(overlay.getPeer()); //overlay is a canvas where MPlayer is embedded.
}
System.out.println(winid);
However, the getPeer() method is deprecated. I would want to know if there's a workaround for it.
Thanks a lot for the help.
I dropped a comment but that deserves an answer. Adding native code, MPlayer, so you are stuck with the impl and the OS. The deprecation of getPeer() is mostly b/c you can do really weird stuff with and not portable.
In your case it doesn't matter.
On a side note: WComponentPeer has a public getHWnd() method, so you do not need to trick it via reflection. The code you have now is actually pretty unsafe since it doesn't check for the actual peer.
you can replace it like that:
long hWnd = 0
try{
Class clazz = Class.forName("sun.awt.windows.WComponentPeer);
synchronized(overlay.getTreeLock()){
ComponentPeer peer = overlay.getPeer();
if (clazz.isInstance(peer)){
hWnd = ((sun.awt.windows.WComponentPeer) overlay.getPeer()).getHWnd();
}
}
}catch(ClassNotFound _noWindows){
//process..
}
good luck!